Tab mute button ignores non-left-clicks (and modifier+left-clicks).
[chromium-blink-merge.git] / sandbox / win / src / handle_table.h
blob47f625d9e376e7a41f36573f769abe0bc2f600df
1 // Copyright (c) 2011 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.
5 #ifndef SANDBOX_SRC_HANDLE_TABLE_H_
6 #define SANDBOX_SRC_HANDLE_TABLE_H_
8 #include <windows.h>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/strings/string16.h"
13 #include "sandbox/win/src/nt_internals.h"
15 namespace sandbox {
17 // HandleTable retrieves the global handle table and provides helper classes
18 // for iterating through the table and retrieving handle info.
19 class HandleTable {
20 public:
21 static const base::char16* HandleTable::kTypeProcess;
22 static const base::char16* HandleTable::kTypeThread;
23 static const base::char16* HandleTable::kTypeFile;
24 static const base::char16* HandleTable::kTypeDirectory;
25 static const base::char16* HandleTable::kTypeKey;
26 static const base::char16* HandleTable::kTypeWindowStation;
27 static const base::char16* HandleTable::kTypeDesktop;
28 static const base::char16* HandleTable::kTypeService;
29 static const base::char16* HandleTable::kTypeMutex;
30 static const base::char16* HandleTable::kTypeSemaphore;
31 static const base::char16* HandleTable::kTypeEvent;
32 static const base::char16* HandleTable::kTypeTimer;
33 static const base::char16* HandleTable::kTypeNamedPipe;
34 static const base::char16* HandleTable::kTypeJobObject;
35 static const base::char16* HandleTable::kTypeFileMap;
36 static const base::char16* HandleTable::kTypeAlpcPort;
38 class Iterator;
40 // Used by the iterator to provide simple caching accessors to handle data.
41 class HandleEntry {
42 public:
43 ~HandleEntry();
45 bool operator==(const HandleEntry& rhs) const {
46 return handle_entry_ == rhs.handle_entry_;
49 bool operator!=(const HandleEntry& rhs) const {
50 return handle_entry_ != rhs.handle_entry_;
53 const SYSTEM_HANDLE_INFORMATION* handle_entry() const {
54 return handle_entry_;
57 const OBJECT_TYPE_INFORMATION* TypeInfo();
59 const base::string16& Name();
61 const base::string16& Type();
63 bool IsType(const base::string16& type_string);
65 private:
66 friend class Iterator;
67 friend class HandleTable;
69 enum UpdateType {
70 UPDATE_INFO_ONLY,
71 UPDATE_INFO_AND_NAME,
72 UPDATE_INFO_AND_TYPE_NAME,
75 explicit HandleEntry(const SYSTEM_HANDLE_INFORMATION* handle_info_entry);
77 bool needs_info_update() { return handle_entry_ != last_entry_; }
79 void UpdateInfo(UpdateType flag);
81 OBJECT_TYPE_INFORMATION* type_info_internal() {
82 return reinterpret_cast<OBJECT_TYPE_INFORMATION*>(
83 &(type_info_buffer_[0]));
86 const SYSTEM_HANDLE_INFORMATION* handle_entry_;
87 const SYSTEM_HANDLE_INFORMATION* last_entry_;
88 std::vector<BYTE> type_info_buffer_;
89 base::string16 handle_name_;
90 base::string16 type_name_;
92 DISALLOW_COPY_AND_ASSIGN(HandleEntry);
95 class Iterator {
96 public:
97 Iterator(const HandleTable& table, const SYSTEM_HANDLE_INFORMATION* start,
98 const SYSTEM_HANDLE_INFORMATION* stop);
100 Iterator(const Iterator& it);
102 Iterator& operator++() {
103 if (++(current_.handle_entry_) == end_)
104 current_.handle_entry_ = table_.end();
105 return *this;
108 bool operator==(const Iterator& rhs) const {
109 return current_ == rhs.current_;
112 bool operator!=(const Iterator& rhs) const {
113 return current_ != rhs.current_;
116 HandleEntry& operator*() { return current_; }
118 operator const SYSTEM_HANDLE_INFORMATION*() {
119 return current_.handle_entry_;
122 HandleEntry* operator->() { return &current_; }
124 private:
125 const HandleTable& table_;
126 HandleEntry current_;
127 const SYSTEM_HANDLE_INFORMATION* end_;
130 HandleTable();
131 ~HandleTable();
133 Iterator begin() const {
134 return Iterator(*this, handle_info()->Information,
135 &handle_info()->Information[handle_info()->NumberOfHandles]);
138 const SYSTEM_HANDLE_INFORMATION_EX* handle_info() const {
139 return reinterpret_cast<const SYSTEM_HANDLE_INFORMATION_EX*>(
140 &(handle_info_buffer_[0]));
143 // Returns an iterator to the handles for only the supplied process ID.
144 Iterator HandlesForProcess(ULONG process_id) const;
145 const SYSTEM_HANDLE_INFORMATION* end() const {
146 return &handle_info()->Information[handle_info()->NumberOfHandles];
149 private:
150 SYSTEM_HANDLE_INFORMATION_EX* handle_info_internal() {
151 return reinterpret_cast<SYSTEM_HANDLE_INFORMATION_EX*>(
152 &(handle_info_buffer_[0]));
155 std::vector<BYTE> handle_info_buffer_;
157 DISALLOW_COPY_AND_ASSIGN(HandleTable);
160 } // namespace sandbox
162 #endif // SANDBOX_SRC_HANDLE_TABLE_H_