1
diff -r f677422fdf56 widget/src/xremoteclient/XRemoteClient.cpp
2
--- a/widget/src/xremoteclient/XRemoteClient.cpp Thu May 14 16:17:53 2009 +0200
3
+++ b/widget/src/xremoteclient/XRemoteClient.cpp Wed Jul 22 11:47:30 2009 +0200
6
static PRLogModuleInfo *sRemoteLm = NULL;
8
+static void trap_errors (const char* trap_name);
9
+static int untrap_error(PRBool log_as_error, PRBool always_log);
11
XRemoteClient::XRemoteClient()
18
+ trap_errors("XRemoteClient::CheckWindow");
19
XGetWindowProperty(mDisplay, aWindow, mMozWMStateAtom,
20
0, 0, False, AnyPropertyType,
21
&type, &format, &nitems, &bytesafter, &data);
23
+ if (untrap_error(PR_TRUE, PR_TRUE))
30
Window root2, parent, *kids;
33
+ trap_errors("XRemoteClient::FindBestWindow - XQueryTree");
34
// Get a list of the children of the root window, walk the list
35
// looking for the best window that fits the criteria.
36
if (!XQueryTree(mDisplay, root, &root2, &parent, &kids, &nkids)) {
38
("XQueryTree failed in XRemoteClient::FindBestWindow"));
41
+ if (untrap_error(PR_TRUE, PR_TRUE))
44
if (!(kids && nkids)) {
45
PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("root window has no children"));
47
// find the inner window with WM_STATE on it
50
+ trap_errors("XRemoteClient::FindBestWindow - XGetWindowProperty 1");
52
int status = XGetWindowProperty(mDisplay, w, mMozVersionAtom,
53
0, (65536 / sizeof (long)),
55
&type, &format, &nitems, &bytesafter,
58
+ if (untrap_error(PR_TRUE, PR_TRUE))
65
// pass in a program name and this window doesn't support that
66
// protocol, we don't include it in our list.
67
if (aProgram && strcmp(aProgram, "any")) {
68
+ trap_errors("XRemoteClient::FindBestWindow - XGetWindowProperty 2");
69
status = XGetWindowProperty(mDisplay, w, mMozProgramAtom,
70
0, (65536 / sizeof(long)),
72
&type, &format, &nitems, &bytesafter,
74
+ if (untrap_error(PR_TRUE, PR_FALSE))
77
// If the return name is not the same as what someone passed in,
78
// we don't want this window.
83
+ trap_errors("XRemoteClient::FindBestWindow - XGetWindowProperty 3");
84
status = XGetWindowProperty(mDisplay, w, mMozUserAtom,
85
0, (65536 / sizeof(long)),
87
&type, &format, &nitems, &bytesafter,
89
+ if (untrap_error(PR_TRUE, PR_FALSE))
92
// if there's a username compare it with what we have
95
// there is, then we need to make sure it matches what someone
98
+ trap_errors("XRemoteClient::FindBestWindow - XGetWindowProperty 4");
99
status = XGetWindowProperty(mDisplay, w, mMozProfileAtom,
100
0, (65536 / sizeof(long)),
102
&type, &format, &nitems, &bytesafter,
104
+ if (untrap_error(PR_TRUE, PR_FALSE))
107
// If there's a profile compare it with what we have
110
unsigned long nitems, bytes_after;
111
unsigned char *data = 0;
113
+ trap_errors("XRemoteClient::FreeLock");
114
result = XGetWindowProperty(mDisplay, aWindow, mMozLockAtom,
115
0, (65536 / sizeof(long)),
116
True, /* atomic delete after */
118
&actual_type, &actual_format,
119
&nitems, &bytes_after,
121
+ if (untrap_error(PR_TRUE, PR_FALSE))
122
+ return NS_ERROR_FAILURE;
124
if (result != Success) {
125
PR_LOG(sRemoteLm, PR_LOG_DEBUG,
126
("unable to read and delete " MOZILLA_LOCK_PROP
132
+static int trapped_error_code = 0;
133
+static int (*old_error_handler) (Display *, XErrorEvent *);
134
+static const char* trap_name = nsnull;
137
+error_handler(Display *display, XErrorEvent *error)
139
+ trapped_error_code = error->error_code;
144
+trap_errors (const char *name)
146
+ trapped_error_code =0;
148
+ old_error_handler = XSetErrorHandler(error_handler);
152
+untrap_error(PRBool log_as_error, PRBool always_log)
154
+ XSetErrorHandler(old_error_handler);
155
+ if((trapped_error_code && log_as_error) || always_log) {
156
+ printf ("XRemoteClient Error - [%s] Get X Window Error = %d\n", trap_name, trapped_error_code);
157
+ PR_LOG(sRemoteLm, PR_LOG_ERROR,
158
+ ("[%s] Get X Window Error = %d", trap_name, trapped_error_code));
160
+ trap_name = nsnull;
161
+ return trapped_error_code;