| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 |
| 5 #ifndef CHROME_BROWSER_PERMISSIONS_DELEGATION_TRACKER_H_ |
| 6 #define CHROME_BROWSER_PERMISSIONS_DELEGATION_TRACKER_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <unordered_map> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/macros.h" |
| 13 |
| 14 namespace content { |
| 15 class RenderFrameHost; |
| 16 class WebContents; |
| 17 enum class PermissionType; |
| 18 } // namespace content |
| 19 |
| 20 // Keeps track of which permissions are delegated to frames. There are two |
| 21 // operations possible: |
| 22 // 1) Setting the permissions which are delegated to a frame by its parent, and |
| 23 // 2) Querying whether a particular permission is granted to a frame. |
| 24 // |
| 25 // If a frame is destroyed or navigated, permissions will no longer be delegated |
| 26 // to it. |
| 27 class DelegationTracker { |
| 28 public: |
| 29 DelegationTracker(); |
| 30 ~DelegationTracker(); |
| 31 |
| 32 // Set the |permissions| which are delegated to |child_rfh| by its parent. |
| 33 void SetDelegatedPermissions( |
| 34 content::RenderFrameHost* child_rfh, |
| 35 const std::vector<content::PermissionType>& permissions); |
| 36 |
| 37 // Query whether |permission| is granted to |requesting_rfh|. This will return |
| 38 // true if |requesting_rfh| is a top-level frame or if it has been delegated |
| 39 // |permission| through its ancestor frames. Specifically, each frame on the |
| 40 // path between the main frame and |requesting_rfh| must either delegate |
| 41 // |permission| to it's child OR have the same origin as it's child on that |
| 42 // path in order for this to return true. |
| 43 bool IsGranted(content::RenderFrameHost* requesting_rfh, |
| 44 const content::PermissionType& permission); |
| 45 |
| 46 private: |
| 47 friend class DelegationTrackerTest; |
| 48 class DelegatedForChild; |
| 49 |
| 50 // Used for testing. |
| 51 void SetDelegatedPermissionsInternal( |
| 52 content::RenderFrameHost* child_rfh, |
| 53 content::WebContents* web_contents, |
| 54 const std::vector<content::PermissionType>& permissions); |
| 55 |
| 56 void RenderFrameHostChanged(content::RenderFrameHost* rfh); |
| 57 |
| 58 std::unordered_map<content::RenderFrameHost*, |
| 59 std::unique_ptr<DelegatedForChild>> |
| 60 delegated_permissions_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(DelegationTracker); |
| 63 }; |
| 64 |
| 65 #endif // CHROME_BROWSER_PERMISSIONS_DELEGATION_TRACKER_H_ |
| OLD | NEW |