Index: chrome/browser/chromeos/extensions/active_tab_permission_granter_delegate_chromeos.cc |
diff --git a/chrome/browser/chromeos/extensions/active_tab_permission_granter_delegate_chromeos.cc b/chrome/browser/chromeos/extensions/active_tab_permission_granter_delegate_chromeos.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ae2f1f78999662a7da2cccf02676098dadb338df |
--- /dev/null |
+++ b/chrome/browser/chromeos/extensions/active_tab_permission_granter_delegate_chromeos.cc |
@@ -0,0 +1,57 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/chromeos/extensions/active_tab_permission_granter_delegate_chromeos.h" |
+ |
+#include <map> |
+ |
+#include "base/lazy_instance.h" |
+#include "chrome/browser/chromeos/extensions/device_local_account_management_policy_provider.h" |
+#include "chrome/browser/chromeos/extensions/public_session_permission_helper.h" |
+#include "chrome/browser/profiles/profiles_state.h" |
+#include "extensions/common/extension.h" |
+#include "extensions/common/permissions/api_permission.h" |
+#include "extensions/common/permissions/api_permission_set.h" |
+ |
+namespace extensions { |
+ |
+namespace { |
+ |
+base::LazyInstance<std::map<ExtensionId, bool>>::Leaky |
+ g_active_tab_granted_map = LAZY_INSTANCE_INITIALIZER; |
+ |
+void UpdateActiveTabGranted(const Extension* extension, |
+ const PermissionIDSet& allowed_permissions) { |
+ g_active_tab_granted_map.Get()[extension->id()] = |
+ allowed_permissions.ContainsID(APIPermission::kActiveTab); |
+} |
+ |
+} // namespace |
+ |
+ActiveTabPermissionGranterDelegateChromeOS:: |
+ ActiveTabPermissionGranterDelegateChromeOS() {} |
+ |
+ActiveTabPermissionGranterDelegateChromeOS:: |
+ ~ActiveTabPermissionGranterDelegateChromeOS() {} |
+ |
+bool ActiveTabPermissionGranterDelegateChromeOS::ActiveTabPermissionGranted( |
+ const Extension* extension, |
+ content::WebContents* web_contents) { |
+ bool active_tab_granted = g_active_tab_granted_map.Get()[extension->id()]; |
+ |
+ if (!profiles::IsPublicSession() || active_tab_granted || |
+ chromeos::DeviceLocalAccountManagementPolicyProvider::IsWhitelisted( |
+ extension->id())) { |
+ return true; |
+ } |
+ |
+ permission_helper::HandlePermissionRequest( |
Ivan Šandrk
2017/05/05 16:24:26
Should I add a brief comment here explaining the m
|
+ *extension, {APIPermission::kActiveTab}, web_contents, |
+ base::Bind(&UpdateActiveTabGranted, extension), |
+ permission_helper::PromptFactory()); |
+ |
+ return false; |
+} |
+ |
+} // namespace extensions |