Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2668)

Unified Diff: chrome/browser/permissions/delegation_tracker.h

Issue 2046293002: Implement DelegationTracker for tracking delegated permissions to RenderFrameHosts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission-delegation-2-blink
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/permissions/delegation_tracker.h
diff --git a/chrome/browser/permissions/delegation_tracker.h b/chrome/browser/permissions/delegation_tracker.h
new file mode 100644
index 0000000000000000000000000000000000000000..65a989830100bcb3e986f27337f37e1bfa476d0c
--- /dev/null
+++ b/chrome/browser/permissions/delegation_tracker.h
@@ -0,0 +1,65 @@
+// Copyright 2016 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.
+
+#ifndef CHROME_BROWSER_PERMISSIONS_DELEGATION_TRACKER_H_
+#define CHROME_BROWSER_PERMISSIONS_DELEGATION_TRACKER_H_
+
+#include <memory>
+#include <unordered_map>
+#include <vector>
+
+#include "base/macros.h"
+
+namespace content {
+class RenderFrameHost;
+class WebContents;
+enum class PermissionType;
+} // namespace content
+
+// Keeps track of which permissions are delegated to frames. There are two
+// operations possible:
+// 1) Setting the permissions which are delegated to a frame by its parent, and
+// 2) Querying whether a particular permission is granted to a frame.
+//
+// If a frame is destroyed or navigated, permissions will no longer be delegated
+// to it.
+class DelegationTracker {
+ public:
+ DelegationTracker();
+ ~DelegationTracker();
+
+ // Set the |permissions| which are delegated to |child_rfh| by its parent.
+ void SetDelegatedPermissions(
+ content::RenderFrameHost* child_rfh,
+ const std::vector<content::PermissionType>& permissions);
+
+ // Query whether |permission| is granted to |requesting_rfh|. This will return
+ // true if |requesting_rfh| is a top-level frame or if it has been delegated
+ // |permission| through its ancestor frames. Specifically, each frame on the
+ // path between the main frame and |requesting_rfh| must either delegate
+ // |permission| to it's child OR have the same origin as it's child on that
+ // path in order for this to return true.
+ bool IsGranted(content::RenderFrameHost* requesting_rfh,
+ const content::PermissionType& permission);
+
+ private:
+ friend class DelegationTrackerTest;
+ class DelegatedForChild;
+
+ // Used for testing.
+ void SetDelegatedPermissionsInternal(
+ content::RenderFrameHost* child_rfh,
+ content::WebContents* web_contents,
+ const std::vector<content::PermissionType>& permissions);
+
+ void RenderFrameHostChanged(content::RenderFrameHost* rfh);
+
+ std::unordered_map<content::RenderFrameHost*,
+ std::unique_ptr<DelegatedForChild>>
+ delegated_permissions_;
+
+ DISALLOW_COPY_AND_ASSIGN(DelegationTracker);
+};
+
+#endif // CHROME_BROWSER_PERMISSIONS_DELEGATION_TRACKER_H_
« no previous file with comments | « no previous file | chrome/browser/permissions/delegation_tracker.cc » ('j') | chrome/browser/permissions/delegation_tracker.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698