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

Side by Side Diff: chrome/browser/ui/views/about_ipc_dialog.cc

Issue 5526008: Simplify the magic required to create IPC message headers a bit. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host.cc ('k') | chrome/common/automation_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Need to include this before any other file because it defines 5 // Need to include this before any other file because it defines
6 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define 6 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define
7 // IPC_MESSAGE_MACROS_LOG_ENABLED so render_messages.h will generate the 7 // IPC_MESSAGE_MACROS_LOG_ENABLED so render_messages.h will generate the
8 // ViewMsgLog et al. functions. 8 // ViewMsgLog et al. functions.
9 #include "ipc/ipc_message.h" 9 #include "ipc/ipc_message.h"
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 kFlagsColumn, 52 kFlagsColumn,
53 kDispatchColumn, 53 kDispatchColumn,
54 kProcessColumn, 54 kProcessColumn,
55 kParamsColumn, 55 kParamsColumn,
56 }; 56 };
57 57
58 // This class registers the browser IPC logger functions with IPC::Logging. 58 // This class registers the browser IPC logger functions with IPC::Logging.
59 class RegisterLoggerFuncs { 59 class RegisterLoggerFuncs {
60 public: 60 public:
61 RegisterLoggerFuncs() { 61 RegisterLoggerFuncs() {
62 IPC::Logging::SetLoggerFunctions(g_log_function_mapping); 62 IPC::Logging::set_log_function_map(&g_log_function_mapping);
63 } 63 }
64 }; 64 };
65 65
66 RegisterLoggerFuncs g_register_logger_funcs; 66 RegisterLoggerFuncs g_register_logger_funcs;
67 67
68 // The singleton dialog box. This is non-NULL when a dialog is active so we 68 // The singleton dialog box. This is non-NULL when a dialog is active so we
69 // know not to create a new one. 69 // know not to create a new one.
70 AboutIPCDialog* active_dialog = NULL; 70 AboutIPCDialog* active_dialog = NULL;
71 71
72 std::set<int> disabled_messages; 72 std::set<int> disabled_messages;
73 73
74 // Settings dialog ------------------------------------------------------------- 74 // Settings dialog -------------------------------------------------------------
75 75
76 bool init_done = false; 76 bool init_done = false;
77 HWND settings_dialog = NULL; 77 HWND settings_dialog = NULL;
78 78 // Settings.
79 // Settings lists. 79 CListViewCtrl* messages = NULL;
80 struct Settings {
81 CListViewCtrl* view;
82 CListViewCtrl* view_host;
83 CListViewCtrl* plugin;
84 CListViewCtrl* plugin_host;
85 CListViewCtrl* npobject;
86 CListViewCtrl* plugin_process;
87 CListViewCtrl* plugin_process_host;
88 CListViewCtrl* devtools_agent;
89 CListViewCtrl* devtools_client;
90
91 } settings_views = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
92
93 void CreateColumn(uint32 start, uint32 end, HWND hwnd,
94 CListViewCtrl** control) {
95 DCHECK(*control == NULL);
96 *control = new CListViewCtrl(hwnd);
97 CListViewCtrl* control_ptr = *control;
98 control_ptr->SetViewType(LVS_REPORT);
99 control_ptr->SetExtendedListViewStyle(LVS_EX_CHECKBOXES);
100 control_ptr->ModifyStyle(0, LVS_SORTASCENDING | LVS_NOCOLUMNHEADER);
101 control_ptr->InsertColumn(0, L"id", LVCFMT_LEFT, 230);
102
103 for (uint32 i = start; i < end; i++) {
104 std::string name;
105 IPC::Logging::GetMessageText(i, &name, NULL, NULL);
106 std::wstring wname = UTF8ToWide(name);
107
108 int index = control_ptr->InsertItem(
109 LVIF_TEXT | LVIF_PARAM, 0, wname.c_str(), 0, 0, 0, i);
110
111 control_ptr->SetItemText(index, 0, wname.c_str());
112
113 if (disabled_messages.find(i) == disabled_messages.end())
114 control_ptr->SetCheckState(index, TRUE);
115 }
116 }
117 80
118 void OnCheck(int id, bool checked) { 81 void OnCheck(int id, bool checked) {
119 if (!init_done) 82 if (!init_done)
120 return; 83 return;
121 84
122 if (checked) 85 if (checked)
123 disabled_messages.erase(id); 86 disabled_messages.erase(id);
124 else 87 else
125 disabled_messages.insert(id); 88 disabled_messages.insert(id);
126 } 89 }
127 90
91 void InitDialog(HWND hwnd) {
92 messages = new CListViewCtrl(::GetDlgItem(hwnd, IDC_Messages));
128 93
129 void CheckButtons(CListViewCtrl* control, bool check) { 94 messages->SetViewType(LVS_REPORT);
130 int count = control->GetItemCount(); 95 messages->SetExtendedListViewStyle(LVS_EX_CHECKBOXES);
131 for (int i = 0; i < count; ++i) 96 messages->ModifyStyle(0, LVS_SORTASCENDING | LVS_NOCOLUMNHEADER);
132 control->SetCheckState(i, check); 97 messages->InsertColumn(0, L"id", LVCFMT_LEFT, 230);
133 }
134 98
135 void InitDialog(HWND hwnd) { 99 LogFunctionMap* log_functions = IPC::Logging::log_function_map();
136 CreateColumn(ViewStart, ViewEnd, ::GetDlgItem(hwnd, IDC_View), 100 for (LogFunctionMap::iterator i = log_functions->begin();
137 &settings_views.view); 101 i != log_functions->end(); ++i) {
138 CreateColumn(ViewHostStart, ViewHostEnd, ::GetDlgItem(hwnd, IDC_ViewHost), 102 std::string name;
139 &settings_views.view_host); 103 (*i->second)(&name, NULL, NULL);
140 CreateColumn(PluginStart, PluginEnd, ::GetDlgItem(hwnd, IDC_Plugin), 104 if (name.empty())
141 &settings_views.plugin); 105 continue; // Will happen if the message file isn't included above.
142 CreateColumn(PluginHostStart, PluginHostEnd, 106 std::wstring wname = UTF8ToWide(name);
143 ::GetDlgItem(hwnd, IDC_PluginHost), 107
144 &settings_views.plugin_host); 108 int index = messages->InsertItem(
145 CreateColumn(NPObjectStart, NPObjectEnd, ::GetDlgItem(hwnd, IDC_NPObject), 109 LVIF_TEXT | LVIF_PARAM, 0, wname.c_str(), 0, 0, 0, i->first);
146 &settings_views.npobject); 110
147 CreateColumn(PluginProcessStart, PluginProcessEnd, 111 messages->SetItemText(index, 0, wname.c_str());
148 ::GetDlgItem(hwnd, IDC_PluginProcess), 112
149 &settings_views.plugin_process); 113 if (disabled_messages.find(i->first) == disabled_messages.end())
150 CreateColumn(PluginProcessHostStart, PluginProcessHostEnd, 114 messages->SetCheckState(index, TRUE);
151 ::GetDlgItem(hwnd, IDC_PluginProcessHost), 115 }
152 &settings_views.plugin_process_host); 116
153 CreateColumn(DevToolsAgentStart, DevToolsAgentEnd,
154 ::GetDlgItem(hwnd, IDC_DevToolsAgent),
155 &settings_views.devtools_agent);
156 CreateColumn(DevToolsClientStart, DevToolsClientEnd,
157 ::GetDlgItem(hwnd, IDC_DevToolsClient),
158 &settings_views.devtools_client);
159 init_done = true; 117 init_done = true;
160 } 118 }
161 119
162 void CloseDialog() { 120 void CloseDialog() {
163 delete settings_views.view; 121 delete messages;
164 delete settings_views.view_host; 122 messages = NULL;
165 delete settings_views.plugin_host;
166 delete settings_views.npobject;
167 delete settings_views.plugin_process;
168 delete settings_views.plugin_process_host;
169 delete settings_views.devtools_agent;
170 delete settings_views.devtools_client;
171 settings_views.view = NULL;
172 settings_views.view_host = NULL;
173 settings_views.plugin = NULL;
174 settings_views.plugin_host = NULL;
175 settings_views.npobject = NULL;
176 settings_views.plugin_process = NULL;
177 settings_views.plugin_process_host = NULL;
178 settings_views.devtools_agent = NULL;
179 settings_views.devtools_client = NULL;
180 123
181 init_done = false; 124 init_done = false;
182 125
183 ::DestroyWindow(settings_dialog); 126 ::DestroyWindow(settings_dialog);
184 settings_dialog = NULL; 127 settings_dialog = NULL;
185 128
186 /* The old version of this code stored the last settings in the preferences. 129 /* The old version of this code stored the last settings in the preferences.
187 But with this dialog, there currently isn't an easy way to get the profile 130 But with this dialog, there currently isn't an easy way to get the profile
188 to asave in the preferences. 131 to save in the preferences.
189 Profile* current_profile = profile(); 132 Profile* current_profile = profile();
190 if (!current_profile) 133 if (!current_profile)
191 return; 134 return;
192 PrefService* prefs = current_profile->GetPrefs(); 135 PrefService* prefs = current_profile->GetPrefs();
193 if (!prefs->FindPreference(prefs::kIpcDisabledMessages)) 136 if (!prefs->FindPreference(prefs::kIpcDisabledMessages))
194 return; 137 return;
195 ListValue* list = prefs->GetMutableList(prefs::kIpcDisabledMessages); 138 ListValue* list = prefs->GetMutableList(prefs::kIpcDisabledMessages);
196 list->Clear(); 139 list->Clear();
197 for (std::set<int>::const_iterator itr = disabled_messages_.begin(); 140 for (std::set<int>::const_iterator itr = disabled_messages_.begin();
198 itr != disabled_messages_.end(); 141 itr != disabled_messages_.end();
199 ++itr) { 142 ++itr) {
200 list->Append(Value::CreateIntegerValue(*itr)); 143 list->Append(Value::CreateIntegerValue(*itr));
201 } 144 }
202 */ 145 */
203 } 146 }
204 147
205 void OnButtonClick(int id) { 148 void OnButtonClick(int id) {
206 switch (id) { 149 int count = messages->GetItemCount();
207 case IDC_ViewAll: 150 for (int i = 0; i < count; ++i)
208 CheckButtons(settings_views.view, true); 151 messages->SetCheckState(i, id == IDC_MessagesAll);
209 break;
210 case IDC_ViewNone:
211 CheckButtons(settings_views.view, false);
212 break;
213 case IDC_ViewHostAll:
214 CheckButtons(settings_views.view_host, true);
215 break;
216 case IDC_ViewHostNone:
217 CheckButtons(settings_views.view_host, false);
218 break;
219 case IDC_PluginAll:
220 CheckButtons(settings_views.plugin, true);
221 break;
222 case IDC_PluginNone:
223 CheckButtons(settings_views.plugin, false);
224 break;
225 case IDC_PluginHostAll:
226 CheckButtons(settings_views.plugin_host, true);
227 break;
228 case IDC_PluginHostNone:
229 CheckButtons(settings_views.plugin_host, false);
230 break;
231 case IDC_NPObjectAll:
232 CheckButtons(settings_views.npobject, true);
233 break;
234 case IDC_NPObjectNone:
235 CheckButtons(settings_views.npobject, false);
236 break;
237 }
238 } 152 }
239 153
240 INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { 154 INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
241 switch (msg) { 155 switch (msg) {
242 case WM_INITDIALOG: 156 case WM_INITDIALOG:
243 InitDialog(hwnd); 157 InitDialog(hwnd);
244 return FALSE; // Don't set keyboard focus. 158 return FALSE; // Don't set keyboard focus.
245 case WM_SYSCOMMAND: 159 case WM_SYSCOMMAND:
246 if (wparam == SC_CLOSE) { 160 if (wparam == SC_CLOSE) {
247 CloseDialog(); 161 CloseDialog();
248 return FALSE; 162 return FALSE;
249 } 163 }
250 break; 164 break;
251 case WM_NOTIFY: { 165 case WM_NOTIFY: {
252 NMLISTVIEW* info = reinterpret_cast<NM_LISTVIEW*>(lparam); 166 NMLISTVIEW* info = reinterpret_cast<NM_LISTVIEW*>(lparam);
253 if ((wparam == IDC_View || wparam == IDC_ViewHost || 167 if (wparam == IDC_Messages && info->hdr.code == LVN_ITEMCHANGED) {
254 wparam == IDC_Plugin ||
255 wparam == IDC_PluginHost || wparam == IDC_NPObject ||
256 wparam == IDC_PluginProcess || wparam == IDC_PluginProcessHost) &&
257 info->hdr.code == LVN_ITEMCHANGED) {
258 if (info->uChanged & LVIF_STATE) { 168 if (info->uChanged & LVIF_STATE) {
259 bool checked = (info->uNewState >> 12) == 2; 169 bool checked = (info->uNewState >> 12) == 2;
260 OnCheck(static_cast<int>(info->lParam), checked); 170 OnCheck(static_cast<int>(info->lParam), checked);
261 } 171 }
262 return FALSE; 172 return FALSE;
263 } 173 }
264 break; 174 break;
265 } 175 }
266 case WM_COMMAND: 176 case WM_COMMAND:
267 if (HIWORD(wparam) == BN_CLICKED) 177 if (HIWORD(wparam) == BN_CLICKED)
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 } 361 }
452 track_toggle_->SchedulePaint(); 362 track_toggle_->SchedulePaint();
453 } else if (button == clear_button_) { 363 } else if (button == clear_button_) {
454 message_list_.DeleteAllItems(); 364 message_list_.DeleteAllItems();
455 } else if (button == filter_button_) { 365 } else if (button == filter_button_) {
456 RunSettingsDialog(GetRootView()->GetWidget()->GetNativeView()); 366 RunSettingsDialog(GetRootView()->GetWidget()->GetNativeView());
457 } 367 }
458 } 368 }
459 369
460 #endif // IPC_MESSAGE_LOG_ENABLED 370 #endif // IPC_MESSAGE_LOG_ENABLED
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host.cc ('k') | chrome/common/automation_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698