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