summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/active_tab_permission_granter.cc
diff options
context:
space:
mode:
authorkalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-18 19:52:42 +0000
committerkalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-18 19:52:42 +0000
commit053ac7169a1f5c78ed59d25e086b003cf7bfbc6f (patch)
treee637ba1db3e8928bf29f4bbeb5b68c921e4be9f9 /chrome/browser/extensions/active_tab_permission_granter.cc
parent1d758b30cfc0d303353fe2a4390bf6ea647c8870 (diff)
downloadchromium_src-053ac7169a1f5c78ed59d25e086b003cf7bfbc6f.zip
chromium_src-053ac7169a1f5c78ed59d25e086b003cf7bfbc6f.tar.gz
chromium_src-053ac7169a1f5c78ed59d25e086b003cf7bfbc6f.tar.bz2
Revert 229235 "Move the tab-lifetime handling functionality out ..."
No longer needed and it adds complexity, so reverting. > Move the tab-lifetime handling functionality out of ActiveTabPermissionGranter > and into a new class TabCapabilityTracker, to make room for web connectable > incognito support for apps. > > BUG=305394 > R=mpcomplete@chromium.org > > Review URL: https://codereview.chromium.org/27604003 TBR=kalman@chromium.org Review URL: https://codereview.chromium.org/29683002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@229453 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/active_tab_permission_granter.cc')
-rw-r--r--chrome/browser/extensions/active_tab_permission_granter.cc77
1 files changed, 52 insertions, 25 deletions
diff --git a/chrome/browser/extensions/active_tab_permission_granter.cc b/chrome/browser/extensions/active_tab_permission_granter.cc
index e94d2d8..8e8c1dc 100644
--- a/chrome/browser/extensions/active_tab_permission_granter.cc
+++ b/chrome/browser/extensions/active_tab_permission_granter.cc
@@ -21,34 +21,32 @@
#include "content/public/browser/web_contents.h"
#include "extensions/common/user_script.h"
+using content::RenderProcessHost;
+using content::WebContentsObserver;
+
namespace extensions {
ActiveTabPermissionGranter::ActiveTabPermissionGranter(
- content::WebContents* web_contents,
- int tab_id,
- Profile* profile)
- : tab_id_(tab_id),
- web_contents_(web_contents),
- tab_capability_tracker_(web_contents, profile) {
- tab_capability_tracker_.AddObserver(this);
+ content::WebContents* web_contents, int tab_id, Profile* profile)
+ : WebContentsObserver(web_contents), tab_id_(tab_id) {
+ registrar_.Add(this,
+ chrome::NOTIFICATION_EXTENSION_UNLOADED,
+ content::Source<Profile>(profile));
}
-ActiveTabPermissionGranter::~ActiveTabPermissionGranter() {
- tab_capability_tracker_.RemoveObserver(this);
-}
+ActiveTabPermissionGranter::~ActiveTabPermissionGranter() {}
void ActiveTabPermissionGranter::GrantIfRequested(const Extension* extension) {
- tab_capability_tracker_.Grant(extension);
-}
+ if (granted_extensions_.Contains(extension->id()))
+ return;
-void ActiveTabPermissionGranter::OnGranted(const Extension* extension) {
APIPermissionSet new_apis;
URLPatternSet new_hosts;
if (extension->HasAPIPermission(APIPermission::kActiveTab)) {
URLPattern pattern(UserScript::ValidUserScriptSchemes());
// Pattern parsing could fail if this is an unsupported URL e.g. chrome://.
- if (pattern.Parse(web_contents_->GetURL().spec()) ==
+ if (pattern.Parse(web_contents()->GetURL().spec()) ==
URLPattern::PARSE_SUCCESS) {
new_hosts.AddPattern(pattern);
}
@@ -59,34 +57,63 @@ void ActiveTabPermissionGranter::OnGranted(const Extension* extension) {
new_apis.insert(APIPermission::kTabCaptureForTab);
if (!new_apis.empty() || !new_hosts.is_empty()) {
+ granted_extensions_.Insert(extension);
scoped_refptr<const PermissionSet> new_permissions =
new PermissionSet(new_apis, new_hosts, URLPatternSet());
PermissionsData::UpdateTabSpecificPermissions(extension,
tab_id_,
new_permissions);
- web_contents_->Send(
- new ExtensionMsg_UpdateTabSpecificPermissions(GetPageID(),
- tab_id_,
- extension->id(),
- new_hosts));
+ Send(new ExtensionMsg_UpdateTabSpecificPermissions(GetPageID(),
+ tab_id_,
+ extension->id(),
+ new_hosts));
}
}
-void ActiveTabPermissionGranter::OnRevoked(const ExtensionSet* extensions) {
+void ActiveTabPermissionGranter::DidNavigateMainFrame(
+ const content::LoadCommittedDetails& details,
+ const content::FrameNavigateParams& params) {
+ if (details.is_in_page)
+ return;
+ DCHECK(details.is_main_frame); // important: sub-frames don't get granted!
+ ClearActiveExtensionsAndNotify();
+}
+
+void ActiveTabPermissionGranter::WebContentsDestroyed(
+ content::WebContents* web_contents) {
+ ClearActiveExtensionsAndNotify();
+}
+
+void ActiveTabPermissionGranter::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_UNLOADED);
+ const Extension* extension =
+ content::Details<UnloadedExtensionInfo>(details)->extension;
+ // Note: don't need to clear the permissions (nor tell the renderer about it)
+ // because it's being unloaded anyway.
+ granted_extensions_.Remove(extension->id());
+}
+
+void ActiveTabPermissionGranter::ClearActiveExtensionsAndNotify() {
+ if (granted_extensions_.is_empty())
+ return;
+
std::vector<std::string> extension_ids;
- for (ExtensionSet::const_iterator it = extensions->begin();
- it != extensions->end(); ++it) {
+ for (ExtensionSet::const_iterator it = granted_extensions_.begin();
+ it != granted_extensions_.end(); ++it) {
PermissionsData::ClearTabSpecificPermissions(it->get(), tab_id_);
extension_ids.push_back((*it)->id());
}
- web_contents_->Send(
- new ExtensionMsg_ClearTabSpecificPermissions(tab_id_, extension_ids));
+ Send(new ExtensionMsg_ClearTabSpecificPermissions(tab_id_, extension_ids));
+ granted_extensions_.Clear();
}
int32 ActiveTabPermissionGranter::GetPageID() {
- return web_contents_->GetController().GetVisibleEntry()->GetPageID();
+ return web_contents()->GetController().GetVisibleEntry()->GetPageID();
}
} // namespace extensions