| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ | 5 #ifndef GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ |
| 6 #define GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ | 6 #define GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // availible and it goes very much against the grain of the code to make it so. | 29 // availible and it goes very much against the grain of the code to make it so. |
| 30 // Also, we worry that GTK might choose to change the underlying X window id | 30 // Also, we worry that GTK might choose to change the underlying X window id |
| 31 // when, say, the widget is hidden or repacked. Finally, if we used XIDs then a | 31 // when, say, the widget is hidden or repacked. Finally, if we used XIDs then a |
| 32 // compromised renderer could start asking questions about any X windows on the | 32 // compromised renderer could start asking questions about any X windows on the |
| 33 // system. | 33 // system. |
| 34 // | 34 // |
| 35 // Thus, we have this object. It produces random NativeViewIds from GtkWidget | 35 // Thus, we have this object. It produces random NativeViewIds from GtkWidget |
| 36 // pointers and observes the various signals from the widget for when an X | 36 // pointers and observes the various signals from the widget for when an X |
| 37 // window is created, destroyed etc. Thus it provides a thread safe mapping | 37 // window is created, destroyed etc. Thus it provides a thread safe mapping |
| 38 // from NativeViewIds to the current XID for that widget. | 38 // from NativeViewIds to the current XID for that widget. |
| 39 // | |
| 40 // You get a reference to the global instance with: | |
| 41 // Singleton<GtkNativeViewManager>() | |
| 42 class GtkNativeViewManager { | 39 class GtkNativeViewManager { |
| 43 public: | 40 public: |
| 41 // Returns the singleton instance. |
| 42 static GtkNativeViewManager* GetInstance(); |
| 43 |
| 44 // Must be called from the UI thread: | 44 // Must be called from the UI thread: |
| 45 // | 45 // |
| 46 // Return a NativeViewId for the given widget and attach to the various | 46 // Return a NativeViewId for the given widget and attach to the various |
| 47 // signals emitted by that widget. The NativeViewId is pseudo-randomly | 47 // signals emitted by that widget. The NativeViewId is pseudo-randomly |
| 48 // allocated so that a compromised renderer trying to guess values will fail | 48 // allocated so that a compromised renderer trying to guess values will fail |
| 49 // with high probability. The NativeViewId will not be reused for the | 49 // with high probability. The NativeViewId will not be reused for the |
| 50 // lifetime of the GtkWidget. | 50 // lifetime of the GtkWidget. |
| 51 gfx::NativeViewId GetIdForWidget(gfx::NativeView widget); | 51 gfx::NativeViewId GetIdForWidget(gfx::NativeView widget); |
| 52 | 52 |
| 53 // May be called from any thread: | 53 // May be called from any thread: |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // | 131 // |
| 132 // An XID will map to NULL, if there is an outstanding reference but the | 132 // An XID will map to NULL, if there is an outstanding reference but the |
| 133 // widget was destroyed. In this case, the destruction of the X window | 133 // widget was destroyed. In this case, the destruction of the X window |
| 134 // is deferred to the dropping of all references. | 134 // is deferred to the dropping of all references. |
| 135 std::map<XID, PermanentXIDInfo> perm_xid_to_info_; | 135 std::map<XID, PermanentXIDInfo> perm_xid_to_info_; |
| 136 | 136 |
| 137 DISALLOW_COPY_AND_ASSIGN(GtkNativeViewManager); | 137 DISALLOW_COPY_AND_ASSIGN(GtkNativeViewManager); |
| 138 }; | 138 }; |
| 139 | 139 |
| 140 #endif // GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ | 140 #endif // GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ |
| OLD | NEW |