/src/mozilla-central/accessible/base/Logging.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
5 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "Logging.h" |
8 | | |
9 | | #include "Accessible-inl.h" |
10 | | #include "AccEvent.h" |
11 | | #include "DocAccessible.h" |
12 | | #include "nsAccessibilityService.h" |
13 | | #include "nsCoreUtils.h" |
14 | | #include "OuterDocAccessible.h" |
15 | | |
16 | | #include "nsDocShellLoadTypes.h" |
17 | | #include "nsIChannel.h" |
18 | | #include "nsIInterfaceRequestorUtils.h" |
19 | | #include "nsISelectionController.h" |
20 | | #include "nsTraceRefcnt.h" |
21 | | #include "nsIWebProgress.h" |
22 | | #include "prenv.h" |
23 | | #include "nsIDocShellTreeItem.h" |
24 | | #include "nsIURI.h" |
25 | | #include "mozilla/dom/Element.h" |
26 | | #include "mozilla/dom/HTMLBodyElement.h" |
27 | | #include "mozilla/dom/Selection.h" |
28 | | |
29 | | using namespace mozilla; |
30 | | using namespace mozilla::a11y; |
31 | | |
32 | | //////////////////////////////////////////////////////////////////////////////// |
33 | | // Logging helpers |
34 | | |
35 | | static uint32_t sModules = 0; |
36 | | |
37 | | struct ModuleRep { |
38 | | const char* mStr; |
39 | | logging::EModules mModule; |
40 | | }; |
41 | | |
42 | | static ModuleRep sModuleMap[] = { |
43 | | { "docload", logging::eDocLoad }, |
44 | | { "doccreate", logging::eDocCreate }, |
45 | | { "docdestroy", logging::eDocDestroy }, |
46 | | { "doclifecycle", logging::eDocLifeCycle }, |
47 | | |
48 | | { "events", logging::eEvents }, |
49 | | { "eventTree", logging::eEventTree }, |
50 | | { "platforms", logging::ePlatforms }, |
51 | | { "text", logging::eText }, |
52 | | { "tree", logging::eTree }, |
53 | | |
54 | | { "DOMEvents", logging::eDOMEvents }, |
55 | | { "focus", logging::eFocus }, |
56 | | { "selection", logging::eSelection }, |
57 | | { "notifications", logging::eNotifications }, |
58 | | |
59 | | { "stack", logging::eStack }, |
60 | | { "verbose", logging::eVerbose } |
61 | | }; |
62 | | |
63 | | static void |
64 | | EnableLogging(const char* aModulesStr) |
65 | 0 | { |
66 | 0 | sModules = 0; |
67 | 0 | if (!aModulesStr) |
68 | 0 | return; |
69 | 0 | |
70 | 0 | const char* token = aModulesStr; |
71 | 0 | while (*token != '\0') { |
72 | 0 | size_t tokenLen = strcspn(token, ","); |
73 | 0 | for (unsigned int idx = 0; idx < ArrayLength(sModuleMap); idx++) { |
74 | 0 | if (strncmp(token, sModuleMap[idx].mStr, tokenLen) == 0) { |
75 | | #if !defined(MOZ_PROFILING) && (!defined(DEBUG) || defined(MOZ_OPTIMIZE)) |
76 | | // Stack tracing on profiling enabled or debug not optimized builds. |
77 | | if (strncmp(token, "stack", tokenLen) == 0) |
78 | | break; |
79 | | #endif |
80 | | sModules |= sModuleMap[idx].mModule; |
81 | 0 | printf("\n\nmodule enabled: %s\n", sModuleMap[idx].mStr); |
82 | 0 | break; |
83 | 0 | } |
84 | 0 | } |
85 | 0 | token += tokenLen; |
86 | 0 |
|
87 | 0 | if (*token == ',') |
88 | 0 | token++; // skip ',' char |
89 | 0 | } |
90 | 0 | } |
91 | | |
92 | | static void |
93 | | LogDocURI(nsIDocument* aDocumentNode) |
94 | 0 | { |
95 | 0 | printf("uri: %s", aDocumentNode->GetDocumentURI()->GetSpecOrDefault().get()); |
96 | 0 | } |
97 | | |
98 | | static void |
99 | | LogDocShellState(nsIDocument* aDocumentNode) |
100 | 0 | { |
101 | 0 | printf("docshell busy: "); |
102 | 0 |
|
103 | 0 | nsAutoCString docShellBusy; |
104 | 0 | nsCOMPtr<nsIDocShell> docShell = aDocumentNode->GetDocShell(); |
105 | 0 | uint32_t busyFlags = nsIDocShell::BUSY_FLAGS_NONE; |
106 | 0 | docShell->GetBusyFlags(&busyFlags); |
107 | 0 | if (busyFlags == nsIDocShell::BUSY_FLAGS_NONE) { |
108 | 0 | printf("'none'"); |
109 | 0 | } |
110 | 0 | if (busyFlags & nsIDocShell::BUSY_FLAGS_BUSY) { |
111 | 0 | printf("'busy'"); |
112 | 0 | } |
113 | 0 | if (busyFlags & nsIDocShell::BUSY_FLAGS_BEFORE_PAGE_LOAD) { |
114 | 0 | printf(", 'before page load'"); |
115 | 0 | } |
116 | 0 | if (busyFlags & nsIDocShell::BUSY_FLAGS_PAGE_LOADING) { |
117 | 0 | printf(", 'page loading'"); |
118 | 0 | } |
119 | 0 | } |
120 | | |
121 | | static void |
122 | | LogDocType(nsIDocument* aDocumentNode) |
123 | 0 | { |
124 | 0 | if (aDocumentNode->IsActive()) { |
125 | 0 | bool isContent = nsCoreUtils::IsContentDocument(aDocumentNode); |
126 | 0 | printf("%s document", (isContent ? "content" : "chrome")); |
127 | 0 | } else { |
128 | 0 | printf("document type: [failed]");\ |
129 | 0 | } |
130 | 0 | } |
131 | | |
132 | | static void |
133 | | LogDocShellTree(nsIDocument* aDocumentNode) |
134 | 0 | { |
135 | 0 | if (aDocumentNode->IsActive()) { |
136 | 0 | nsCOMPtr<nsIDocShellTreeItem> treeItem(aDocumentNode->GetDocShell()); |
137 | 0 | nsCOMPtr<nsIDocShellTreeItem> parentTreeItem; |
138 | 0 | treeItem->GetParent(getter_AddRefs(parentTreeItem)); |
139 | 0 | nsCOMPtr<nsIDocShellTreeItem> rootTreeItem; |
140 | 0 | treeItem->GetRootTreeItem(getter_AddRefs(rootTreeItem)); |
141 | 0 | printf("docshell hierarchy, parent: %p, root: %p, is tab document: %s;", |
142 | 0 | static_cast<void*>(parentTreeItem), static_cast<void*>(rootTreeItem), |
143 | 0 | (nsCoreUtils::IsTabDocument(aDocumentNode) ? "yes" : "no")); |
144 | 0 | } |
145 | 0 | } |
146 | | |
147 | | static void |
148 | | LogDocState(nsIDocument* aDocumentNode) |
149 | 0 | { |
150 | 0 | const char* docState = nullptr; |
151 | 0 | nsIDocument::ReadyState docStateFlag = aDocumentNode->GetReadyStateEnum(); |
152 | 0 | switch (docStateFlag) { |
153 | 0 | case nsIDocument::READYSTATE_UNINITIALIZED: |
154 | 0 | docState = "uninitialized"; |
155 | 0 | break; |
156 | 0 | case nsIDocument::READYSTATE_LOADING: |
157 | 0 | docState = "loading"; |
158 | 0 | break; |
159 | 0 | case nsIDocument::READYSTATE_INTERACTIVE: |
160 | 0 | docState = "interactive"; |
161 | 0 | break; |
162 | 0 | case nsIDocument::READYSTATE_COMPLETE: |
163 | 0 | docState = "complete"; |
164 | 0 | break; |
165 | 0 | } |
166 | 0 | |
167 | 0 | printf("doc state: %s", docState); |
168 | 0 | printf(", %sinitial", aDocumentNode->IsInitialDocument() ? "" : "not "); |
169 | 0 | printf(", %sshowing", aDocumentNode->IsShowing() ? "" : "not "); |
170 | 0 | printf(", %svisible", aDocumentNode->IsVisible() ? "" : "not "); |
171 | 0 | printf(", %svisible considering ancestors", aDocumentNode->IsVisibleConsideringAncestors() ? "" : "not "); |
172 | 0 | printf(", %sactive", aDocumentNode->IsActive() ? "" : "not "); |
173 | 0 | printf(", %sresource", aDocumentNode->IsResourceDoc() ? "" : "not "); |
174 | 0 |
|
175 | 0 | dom::Element* rootEl = aDocumentNode->GetBodyElement(); |
176 | 0 | if (!rootEl) { |
177 | 0 | rootEl = aDocumentNode->GetRootElement(); |
178 | 0 | } |
179 | 0 | printf(", has %srole content", rootEl ? "" : "no "); |
180 | 0 | } |
181 | | |
182 | | static void |
183 | | LogPresShell(nsIDocument* aDocumentNode) |
184 | 0 | { |
185 | 0 | nsIPresShell* ps = aDocumentNode->GetShell(); |
186 | 0 | printf("presshell: %p", static_cast<void*>(ps)); |
187 | 0 |
|
188 | 0 | nsIScrollableFrame* sf = nullptr; |
189 | 0 | if (ps) { |
190 | 0 | printf(", is %s destroying", (ps->IsDestroying() ? "" : "not")); |
191 | 0 | sf = ps->GetRootScrollFrameAsScrollable(); |
192 | 0 | } |
193 | 0 | printf(", root scroll frame: %p", static_cast<void*>(sf)); |
194 | 0 | } |
195 | | |
196 | | static void |
197 | | LogDocLoadGroup(nsIDocument* aDocumentNode) |
198 | 0 | { |
199 | 0 | nsCOMPtr<nsILoadGroup> loadGroup = aDocumentNode->GetDocumentLoadGroup(); |
200 | 0 | printf("load group: %p", static_cast<void*>(loadGroup)); |
201 | 0 | } |
202 | | |
203 | | static void |
204 | | LogDocParent(nsIDocument* aDocumentNode) |
205 | 0 | { |
206 | 0 | nsIDocument* parentDoc = aDocumentNode->GetParentDocument(); |
207 | 0 | printf("parent DOM document: %p", static_cast<void*>(parentDoc)); |
208 | 0 | if (parentDoc) { |
209 | 0 | printf(", parent acc document: %p", |
210 | 0 | static_cast<void*>(GetExistingDocAccessible(parentDoc))); |
211 | 0 | printf("\n parent "); |
212 | 0 | LogDocURI(parentDoc); |
213 | 0 | printf("\n"); |
214 | 0 | } |
215 | 0 | } |
216 | | |
217 | | static void |
218 | | LogDocInfo(nsIDocument* aDocumentNode, DocAccessible* aDocument) |
219 | 0 | { |
220 | 0 | printf(" DOM document: %p, acc document: %p\n ", |
221 | 0 | static_cast<void*>(aDocumentNode), static_cast<void*>(aDocument)); |
222 | 0 |
|
223 | 0 | // log document info |
224 | 0 | if (aDocumentNode) { |
225 | 0 | LogDocURI(aDocumentNode); |
226 | 0 | printf("\n "); |
227 | 0 | LogDocShellState(aDocumentNode); |
228 | 0 | printf("; "); |
229 | 0 | LogDocType(aDocumentNode); |
230 | 0 | printf("\n "); |
231 | 0 | LogDocShellTree(aDocumentNode); |
232 | 0 | printf("\n "); |
233 | 0 | LogDocState(aDocumentNode); |
234 | 0 | printf("\n "); |
235 | 0 | LogPresShell(aDocumentNode); |
236 | 0 | printf("\n "); |
237 | 0 | LogDocLoadGroup(aDocumentNode); |
238 | 0 | printf(", "); |
239 | 0 | LogDocParent(aDocumentNode); |
240 | 0 | printf("\n"); |
241 | 0 | } |
242 | 0 | } |
243 | | |
244 | | static void |
245 | | LogShellLoadType(nsIDocShell* aDocShell) |
246 | | { |
247 | | printf("load type: "); |
248 | | |
249 | | uint32_t loadType = 0; |
250 | | aDocShell->GetLoadType(&loadType); |
251 | | switch (loadType) { |
252 | | case LOAD_NORMAL: |
253 | | printf("normal; "); |
254 | | break; |
255 | | case LOAD_NORMAL_REPLACE: |
256 | | printf("normal replace; "); |
257 | | break; |
258 | | case LOAD_NORMAL_EXTERNAL: |
259 | | printf("normal external; "); |
260 | | break; |
261 | | case LOAD_HISTORY: |
262 | | printf("history; "); |
263 | | break; |
264 | | case LOAD_NORMAL_BYPASS_CACHE: |
265 | | printf("normal bypass cache; "); |
266 | | break; |
267 | | case LOAD_NORMAL_BYPASS_PROXY: |
268 | | printf("normal bypass proxy; "); |
269 | | break; |
270 | | case LOAD_NORMAL_BYPASS_PROXY_AND_CACHE: |
271 | | printf("normal bypass proxy and cache; "); |
272 | | break; |
273 | | case LOAD_NORMAL_ALLOW_MIXED_CONTENT: |
274 | | printf("normal allow mixed content; "); |
275 | | break; |
276 | | case LOAD_RELOAD_NORMAL: |
277 | | printf("reload normal; "); |
278 | | break; |
279 | | case LOAD_RELOAD_BYPASS_CACHE: |
280 | | printf("reload bypass cache; "); |
281 | | break; |
282 | | case LOAD_RELOAD_BYPASS_PROXY: |
283 | | printf("reload bypass proxy; "); |
284 | | break; |
285 | | case LOAD_RELOAD_BYPASS_PROXY_AND_CACHE: |
286 | | printf("reload bypass proxy and cache; "); |
287 | | break; |
288 | | case LOAD_RELOAD_ALLOW_MIXED_CONTENT: |
289 | | printf("reload allow mixed content; "); |
290 | | break; |
291 | | case LOAD_LINK: |
292 | | printf("link; "); |
293 | | break; |
294 | | case LOAD_REFRESH: |
295 | | printf("refresh; "); |
296 | | break; |
297 | | case LOAD_RELOAD_CHARSET_CHANGE: |
298 | | printf("reload charset change; "); |
299 | | break; |
300 | | case LOAD_BYPASS_HISTORY: |
301 | | printf("bypass history; "); |
302 | | break; |
303 | | case LOAD_STOP_CONTENT: |
304 | | printf("stop content; "); |
305 | | break; |
306 | | case LOAD_STOP_CONTENT_AND_REPLACE: |
307 | | printf("stop content and replace; "); |
308 | | break; |
309 | | case LOAD_PUSHSTATE: |
310 | | printf("load pushstate; "); |
311 | | break; |
312 | | case LOAD_REPLACE_BYPASS_CACHE: |
313 | | printf("replace bypass cache; "); |
314 | | break; |
315 | | case LOAD_ERROR_PAGE: |
316 | | printf("error page;"); |
317 | | break; |
318 | | default: |
319 | | printf("unknown"); |
320 | | } |
321 | | } |
322 | | |
323 | | static void |
324 | | LogRequest(nsIRequest* aRequest) |
325 | 0 | { |
326 | 0 | if (aRequest) { |
327 | 0 | nsAutoCString name; |
328 | 0 | aRequest->GetName(name); |
329 | 0 | printf(" request spec: %s\n", name.get()); |
330 | 0 | uint32_t loadFlags = 0; |
331 | 0 | aRequest->GetLoadFlags(&loadFlags); |
332 | 0 | printf(" request load flags: %x; ", loadFlags); |
333 | 0 | if (loadFlags & nsIChannel::LOAD_DOCUMENT_URI) |
334 | 0 | printf("document uri; "); |
335 | 0 | if (loadFlags & nsIChannel::LOAD_RETARGETED_DOCUMENT_URI) |
336 | 0 | printf("retargeted document uri; "); |
337 | 0 | if (loadFlags & nsIChannel::LOAD_REPLACE) |
338 | 0 | printf("replace; "); |
339 | 0 | if (loadFlags & nsIChannel::LOAD_INITIAL_DOCUMENT_URI) |
340 | 0 | printf("initial document uri; "); |
341 | 0 | if (loadFlags & nsIChannel::LOAD_TARGETED) |
342 | 0 | printf("targeted; "); |
343 | 0 | if (loadFlags & nsIChannel::LOAD_CALL_CONTENT_SNIFFERS) |
344 | 0 | printf("call content sniffers; "); |
345 | 0 | if (loadFlags & nsIChannel::LOAD_CLASSIFY_URI) |
346 | 0 | printf("classify uri; "); |
347 | 0 | } else { |
348 | 0 | printf(" no request"); |
349 | 0 | } |
350 | 0 | } |
351 | | |
352 | | static void |
353 | | LogDocAccState(DocAccessible* aDocument) |
354 | 0 | { |
355 | 0 | printf("document acc state: "); |
356 | 0 | if (aDocument->HasLoadState(DocAccessible::eCompletelyLoaded)) |
357 | 0 | printf("completely loaded;"); |
358 | 0 | else if (aDocument->HasLoadState(DocAccessible::eReady)) |
359 | 0 | printf("ready;"); |
360 | 0 | else if (aDocument->HasLoadState(DocAccessible::eDOMLoaded)) |
361 | 0 | printf("DOM loaded;"); |
362 | 0 | else if (aDocument->HasLoadState(DocAccessible::eTreeConstructed)) |
363 | 0 | printf("tree constructed;"); |
364 | 0 | } |
365 | | |
366 | | static void |
367 | | GetDocLoadEventType(AccEvent* aEvent, nsACString& aEventType) |
368 | 0 | { |
369 | 0 | uint32_t type = aEvent->GetEventType(); |
370 | 0 | if (type == nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_STOPPED) { |
371 | 0 | aEventType.AssignLiteral("load stopped"); |
372 | 0 | } else if (type == nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_COMPLETE) { |
373 | 0 | aEventType.AssignLiteral("load complete"); |
374 | 0 | } else if (type == nsIAccessibleEvent::EVENT_DOCUMENT_RELOAD) { |
375 | 0 | aEventType.AssignLiteral("reload"); |
376 | 0 | } else if (type == nsIAccessibleEvent::EVENT_STATE_CHANGE) { |
377 | 0 | AccStateChangeEvent* event = downcast_accEvent(aEvent); |
378 | 0 | if (event->GetState() == states::BUSY) { |
379 | 0 | aEventType.AssignLiteral("busy "); |
380 | 0 | if (event->IsStateEnabled()) |
381 | 0 | aEventType.AppendLiteral("true"); |
382 | 0 | else |
383 | 0 | aEventType.AppendLiteral("false"); |
384 | 0 | } |
385 | 0 | } |
386 | 0 | } |
387 | | |
388 | | //////////////////////////////////////////////////////////////////////////////// |
389 | | // namespace logging:: document life cycle logging methods |
390 | | |
391 | | static const char* sDocLoadTitle = "DOCLOAD"; |
392 | | static const char* sDocCreateTitle = "DOCCREATE"; |
393 | | static const char* sDocDestroyTitle = "DOCDESTROY"; |
394 | | static const char* sDocEventTitle = "DOCEVENT"; |
395 | | static const char* sFocusTitle = "FOCUS"; |
396 | | |
397 | | void |
398 | | logging::DocLoad(const char* aMsg, nsIWebProgress* aWebProgress, |
399 | | nsIRequest* aRequest, uint32_t aStateFlags) |
400 | 0 | { |
401 | 0 | MsgBegin(sDocLoadTitle, "%s", aMsg); |
402 | 0 |
|
403 | 0 | nsCOMPtr<mozIDOMWindowProxy> DOMWindow; |
404 | 0 | aWebProgress->GetDOMWindow(getter_AddRefs(DOMWindow)); |
405 | 0 | nsPIDOMWindowOuter* window = nsPIDOMWindowOuter::From(DOMWindow); |
406 | 0 | if (!window) { |
407 | 0 | MsgEnd(); |
408 | 0 | return; |
409 | 0 | } |
410 | 0 | |
411 | 0 | nsCOMPtr<nsIDocument> documentNode = window->GetDoc(); |
412 | 0 | if (!documentNode) { |
413 | 0 | MsgEnd(); |
414 | 0 | return; |
415 | 0 | } |
416 | 0 | |
417 | 0 | DocAccessible* document = GetExistingDocAccessible(documentNode); |
418 | 0 |
|
419 | 0 | LogDocInfo(documentNode, document); |
420 | 0 |
|
421 | 0 | nsCOMPtr<nsIDocShell> docShell = window->GetDocShell(); |
422 | 0 | printf("\n "); |
423 | 0 | LogShellLoadType(docShell); |
424 | 0 | printf("\n"); |
425 | 0 | LogRequest(aRequest); |
426 | 0 | printf("\n"); |
427 | 0 | printf(" state flags: %x", aStateFlags); |
428 | 0 | bool isDocLoading; |
429 | 0 | aWebProgress->GetIsLoadingDocument(&isDocLoading); |
430 | 0 | printf(", document is %sloading\n", (isDocLoading ? "" : "not ")); |
431 | 0 |
|
432 | 0 | MsgEnd(); |
433 | 0 | } |
434 | | |
435 | | void |
436 | | logging::DocLoad(const char* aMsg, nsIDocument* aDocumentNode) |
437 | 0 | { |
438 | 0 | MsgBegin(sDocLoadTitle, "%s", aMsg); |
439 | 0 |
|
440 | 0 | DocAccessible* document = GetExistingDocAccessible(aDocumentNode); |
441 | 0 | LogDocInfo(aDocumentNode, document); |
442 | 0 |
|
443 | 0 | MsgEnd(); |
444 | 0 | } |
445 | | |
446 | | void |
447 | | logging::DocCompleteLoad(DocAccessible* aDocument, bool aIsLoadEventTarget) |
448 | 0 | { |
449 | 0 | MsgBegin(sDocLoadTitle, "document loaded *completely*"); |
450 | 0 |
|
451 | 0 | printf(" DOM document: %p, acc document: %p\n", |
452 | 0 | static_cast<void*>(aDocument->DocumentNode()), |
453 | 0 | static_cast<void*>(aDocument)); |
454 | 0 |
|
455 | 0 | printf(" "); |
456 | 0 | LogDocURI(aDocument->DocumentNode()); |
457 | 0 | printf("\n"); |
458 | 0 |
|
459 | 0 | printf(" "); |
460 | 0 | LogDocAccState(aDocument); |
461 | 0 | printf("\n"); |
462 | 0 |
|
463 | 0 | printf(" document is load event target: %s\n", |
464 | 0 | (aIsLoadEventTarget ? "true" : "false")); |
465 | 0 |
|
466 | 0 | MsgEnd(); |
467 | 0 | } |
468 | | |
469 | | void |
470 | | logging::DocLoadEventFired(AccEvent* aEvent) |
471 | 0 | { |
472 | 0 | nsAutoCString strEventType; |
473 | 0 | GetDocLoadEventType(aEvent, strEventType); |
474 | 0 | if (!strEventType.IsEmpty()) |
475 | 0 | printf(" fire: %s\n", strEventType.get()); |
476 | 0 | } |
477 | | |
478 | | void |
479 | | logging::DocLoadEventHandled(AccEvent* aEvent) |
480 | 0 | { |
481 | 0 | nsAutoCString strEventType; |
482 | 0 | GetDocLoadEventType(aEvent, strEventType); |
483 | 0 | if (strEventType.IsEmpty()) |
484 | 0 | return; |
485 | 0 | |
486 | 0 | MsgBegin(sDocEventTitle, "handled '%s' event", strEventType.get()); |
487 | 0 |
|
488 | 0 | DocAccessible* document = aEvent->GetAccessible()->AsDoc(); |
489 | 0 | if (document) |
490 | 0 | LogDocInfo(document->DocumentNode(), document); |
491 | 0 |
|
492 | 0 | MsgEnd(); |
493 | 0 | } |
494 | | |
495 | | void |
496 | | logging::DocCreate(const char* aMsg, nsIDocument* aDocumentNode, |
497 | | DocAccessible* aDocument) |
498 | 0 | { |
499 | 0 | DocAccessible* document = aDocument ? |
500 | 0 | aDocument : GetExistingDocAccessible(aDocumentNode); |
501 | 0 |
|
502 | 0 | MsgBegin(sDocCreateTitle, "%s", aMsg); |
503 | 0 | LogDocInfo(aDocumentNode, document); |
504 | 0 | MsgEnd(); |
505 | 0 | } |
506 | | |
507 | | void |
508 | | logging::DocDestroy(const char* aMsg, nsIDocument* aDocumentNode, |
509 | | DocAccessible* aDocument) |
510 | 0 | { |
511 | 0 | DocAccessible* document = aDocument ? |
512 | 0 | aDocument : GetExistingDocAccessible(aDocumentNode); |
513 | 0 |
|
514 | 0 | MsgBegin(sDocDestroyTitle, "%s", aMsg); |
515 | 0 | LogDocInfo(aDocumentNode, document); |
516 | 0 | MsgEnd(); |
517 | 0 | } |
518 | | |
519 | | void |
520 | | logging::OuterDocDestroy(OuterDocAccessible* aOuterDoc) |
521 | 0 | { |
522 | 0 | MsgBegin(sDocDestroyTitle, "outerdoc shutdown"); |
523 | 0 | logging::Address("outerdoc", aOuterDoc); |
524 | 0 | MsgEnd(); |
525 | 0 | } |
526 | | |
527 | | void |
528 | | logging::FocusNotificationTarget(const char* aMsg, const char* aTargetDescr, |
529 | | Accessible* aTarget) |
530 | 0 | { |
531 | 0 | MsgBegin(sFocusTitle, "%s", aMsg); |
532 | 0 | AccessibleNNode(aTargetDescr, aTarget); |
533 | 0 | MsgEnd(); |
534 | 0 | } |
535 | | |
536 | | void |
537 | | logging::FocusNotificationTarget(const char* aMsg, const char* aTargetDescr, |
538 | | nsINode* aTargetNode) |
539 | 0 | { |
540 | 0 | MsgBegin(sFocusTitle, "%s", aMsg); |
541 | 0 | Node(aTargetDescr, aTargetNode); |
542 | 0 | MsgEnd(); |
543 | 0 | } |
544 | | |
545 | | void |
546 | | logging::FocusNotificationTarget(const char* aMsg, const char* aTargetDescr, |
547 | | nsISupports* aTargetThing) |
548 | 0 | { |
549 | 0 | MsgBegin(sFocusTitle, "%s", aMsg); |
550 | 0 |
|
551 | 0 | if (aTargetThing) { |
552 | 0 | nsCOMPtr<nsINode> targetNode(do_QueryInterface(aTargetThing)); |
553 | 0 | if (targetNode) |
554 | 0 | AccessibleNNode(aTargetDescr, targetNode); |
555 | 0 | else |
556 | 0 | printf(" %s: %p, window\n", aTargetDescr, |
557 | 0 | static_cast<void*>(aTargetThing)); |
558 | 0 | } |
559 | 0 |
|
560 | 0 | MsgEnd(); |
561 | 0 | } |
562 | | |
563 | | void |
564 | | logging::ActiveItemChangeCausedBy(const char* aCause, Accessible* aTarget) |
565 | 0 | { |
566 | 0 | SubMsgBegin(); |
567 | 0 | printf(" Caused by: %s\n", aCause); |
568 | 0 | AccessibleNNode("Item", aTarget); |
569 | 0 | SubMsgEnd(); |
570 | 0 | } |
571 | | |
572 | | void |
573 | | logging::ActiveWidget(Accessible* aWidget) |
574 | 0 | { |
575 | 0 | SubMsgBegin(); |
576 | 0 |
|
577 | 0 | AccessibleNNode("Widget", aWidget); |
578 | 0 | printf(" Widget is active: %s, has operable items: %s\n", |
579 | 0 | (aWidget && aWidget->IsActiveWidget() ? "true" : "false"), |
580 | 0 | (aWidget && aWidget->AreItemsOperable() ? "true" : "false")); |
581 | 0 |
|
582 | 0 | SubMsgEnd(); |
583 | 0 | } |
584 | | |
585 | | void |
586 | | logging::FocusDispatched(Accessible* aTarget) |
587 | 0 | { |
588 | 0 | SubMsgBegin(); |
589 | 0 | AccessibleNNode("A11y target", aTarget); |
590 | 0 | SubMsgEnd(); |
591 | 0 | } |
592 | | |
593 | | void |
594 | | logging::SelChange(dom::Selection* aSelection, DocAccessible* aDocument, |
595 | | int16_t aReason) |
596 | 0 | { |
597 | 0 | SelectionType type = aSelection->GetType(); |
598 | 0 |
|
599 | 0 | const char* strType = 0; |
600 | 0 | if (type == SelectionType::eNormal) |
601 | 0 | strType = "normal"; |
602 | 0 | else if (type == SelectionType::eSpellCheck) |
603 | 0 | strType = "spellcheck"; |
604 | 0 | else |
605 | 0 | strType = "unknown"; |
606 | 0 |
|
607 | 0 | bool isIgnored = !aDocument || !aDocument->IsContentLoaded(); |
608 | 0 | printf("\nSelection changed, selection type: %s, notification %s, reason: %d\n", |
609 | 0 | strType, (isIgnored ? "ignored" : "pending"), aReason); |
610 | 0 |
|
611 | 0 | Stack(); |
612 | 0 | } |
613 | | |
614 | | void |
615 | | logging::TreeInfo(const char* aMsg, uint32_t aExtraFlags, ...) |
616 | 0 | { |
617 | 0 | if (IsEnabledAll(logging::eTree | aExtraFlags)) { |
618 | 0 | va_list vl; |
619 | 0 | va_start(vl, aExtraFlags); |
620 | 0 | const char* descr = va_arg(vl, const char*); |
621 | 0 | if (descr) { |
622 | 0 | Accessible* acc = va_arg(vl, Accessible*); |
623 | 0 | MsgBegin("TREE", "%s; doc: %p", aMsg, acc ? acc->Document() : nullptr); |
624 | 0 | AccessibleInfo(descr, acc); |
625 | 0 | while ((descr = va_arg(vl, const char*))) { |
626 | 0 | AccessibleInfo(descr, va_arg(vl, Accessible*)); |
627 | 0 | } |
628 | 0 | } |
629 | 0 | else { |
630 | 0 | MsgBegin("TREE", "%s", aMsg); |
631 | 0 | } |
632 | 0 | va_end(vl); |
633 | 0 | MsgEnd(); |
634 | 0 |
|
635 | 0 | if (aExtraFlags & eStack) { |
636 | 0 | Stack(); |
637 | 0 | } |
638 | 0 | } |
639 | 0 | } |
640 | | |
641 | | void |
642 | | logging::TreeInfo(const char* aMsg, uint32_t aExtraFlags, |
643 | | const char* aMsg1, Accessible* aAcc, |
644 | | const char* aMsg2, nsINode* aNode) |
645 | 0 | { |
646 | 0 | if (IsEnabledAll(logging::eTree | aExtraFlags)) { |
647 | 0 | MsgBegin("TREE", "%s; doc: %p", aMsg, aAcc ? aAcc->Document() : nullptr); |
648 | 0 | AccessibleInfo(aMsg1, aAcc); |
649 | 0 | Accessible* acc = aAcc ? aAcc->Document()->GetAccessible(aNode) : nullptr; |
650 | 0 | if (acc) { |
651 | 0 | AccessibleInfo(aMsg2, acc); |
652 | 0 | } |
653 | 0 | else { |
654 | 0 | Node(aMsg2, aNode); |
655 | 0 | } |
656 | 0 | MsgEnd(); |
657 | 0 | } |
658 | 0 | } |
659 | | |
660 | | |
661 | | void |
662 | | logging::TreeInfo(const char* aMsg, uint32_t aExtraFlags, Accessible* aParent) |
663 | 0 | { |
664 | 0 | if (IsEnabledAll(logging::eTree | aExtraFlags)) { |
665 | 0 | MsgBegin("TREE", "%s; doc: %p", aMsg, aParent->Document()); |
666 | 0 | AccessibleInfo("container", aParent); |
667 | 0 | for (uint32_t idx = 0; idx < aParent->ChildCount(); idx++) { |
668 | 0 | AccessibleInfo("child", aParent->GetChildAt(idx)); |
669 | 0 | } |
670 | 0 | MsgEnd(); |
671 | 0 | } |
672 | 0 | } |
673 | | |
674 | | void |
675 | | logging::Tree(const char* aTitle, const char* aMsgText, |
676 | | Accessible* aRoot, GetTreePrefix aPrefixFunc, |
677 | | void* aGetTreePrefixData) |
678 | 0 | { |
679 | 0 | logging::MsgBegin(aTitle, "%s", aMsgText); |
680 | 0 |
|
681 | 0 | nsAutoString level; |
682 | 0 | Accessible* root = aRoot; |
683 | 0 | do { |
684 | 0 | const char* prefix = aPrefixFunc ? aPrefixFunc(aGetTreePrefixData, root) : ""; |
685 | 0 | printf("%s", NS_ConvertUTF16toUTF8(level).get()); |
686 | 0 | logging::AccessibleInfo(prefix, root); |
687 | 0 | if (root->FirstChild() && !root->FirstChild()->IsDoc()) { |
688 | 0 | level.AppendLiteral(u" "); |
689 | 0 | root = root->FirstChild(); |
690 | 0 | continue; |
691 | 0 | } |
692 | 0 | int32_t idxInParent = root != aRoot && root->mParent ? |
693 | 0 | root->mParent->mChildren.IndexOf(root) : -1; |
694 | 0 | if (idxInParent != -1 && |
695 | 0 | idxInParent < static_cast<int32_t>(root->mParent->mChildren.Length() - 1)) { |
696 | 0 | root = root->mParent->mChildren.ElementAt(idxInParent + 1); |
697 | 0 | continue; |
698 | 0 | } |
699 | 0 | while (root != aRoot && (root = root->Parent())) { |
700 | 0 | level.Cut(0, 2); |
701 | 0 | int32_t idxInParent = !root->IsDoc() && root->mParent ? |
702 | 0 | root->mParent->mChildren.IndexOf(root) : -1; |
703 | 0 | if (idxInParent != -1 && |
704 | 0 | idxInParent < static_cast<int32_t>(root->mParent->mChildren.Length() - 1)) { |
705 | 0 | root = root->mParent->mChildren.ElementAt(idxInParent + 1); |
706 | 0 | break; |
707 | 0 | } |
708 | 0 | } |
709 | 0 | } |
710 | 0 | while (root && root != aRoot); |
711 | 0 |
|
712 | 0 | logging::MsgEnd(); |
713 | 0 | } |
714 | | |
715 | | void |
716 | | logging::DOMTree(const char* aTitle, const char* aMsgText, |
717 | | DocAccessible* aDocument) |
718 | 0 | { |
719 | 0 | logging::MsgBegin(aTitle, "%s", aMsgText); |
720 | 0 | nsAutoString level; |
721 | 0 | nsINode* root = aDocument->DocumentNode(); |
722 | 0 | do { |
723 | 0 | printf("%s", NS_ConvertUTF16toUTF8(level).get()); |
724 | 0 | logging::Node("", root); |
725 | 0 | if (root->GetFirstChild()) { |
726 | 0 | level.AppendLiteral(u" "); |
727 | 0 | root = root->GetFirstChild(); |
728 | 0 | continue; |
729 | 0 | } |
730 | 0 | if (root->GetNextSibling()) { |
731 | 0 | root = root->GetNextSibling(); |
732 | 0 | continue; |
733 | 0 | } |
734 | 0 | while ((root = root->GetParentNode())) { |
735 | 0 | level.Cut(0, 2); |
736 | 0 | if (root->GetNextSibling()) { |
737 | 0 | root = root->GetNextSibling(); |
738 | 0 | break; |
739 | 0 | } |
740 | 0 | } |
741 | 0 | } |
742 | 0 | while (root); |
743 | 0 | logging::MsgEnd(); |
744 | 0 | } |
745 | | |
746 | | void |
747 | | logging::MsgBegin(const char* aTitle, const char* aMsgText, ...) |
748 | 0 | { |
749 | 0 | printf("\nA11Y %s: ", aTitle); |
750 | 0 |
|
751 | 0 | va_list argptr; |
752 | 0 | va_start(argptr, aMsgText); |
753 | 0 | vprintf(aMsgText, argptr); |
754 | 0 | va_end(argptr); |
755 | 0 |
|
756 | 0 | PRIntervalTime time = PR_IntervalNow(); |
757 | 0 | uint32_t mins = (PR_IntervalToSeconds(time) / 60) % 60; |
758 | 0 | uint32_t secs = PR_IntervalToSeconds(time) % 60; |
759 | 0 | uint32_t msecs = PR_IntervalToMilliseconds(time) % 1000; |
760 | 0 | printf("; %02u:%02u.%03u", mins, secs, msecs); |
761 | 0 |
|
762 | 0 | printf("\n {\n"); |
763 | 0 | } |
764 | | |
765 | | void |
766 | | logging::MsgEnd() |
767 | 0 | { |
768 | 0 | printf(" }\n"); |
769 | 0 | } |
770 | | |
771 | | void |
772 | | logging::SubMsgBegin() |
773 | 0 | { |
774 | 0 | printf(" {\n"); |
775 | 0 | } |
776 | | |
777 | | void |
778 | | logging::SubMsgEnd() |
779 | 0 | { |
780 | 0 | printf(" }\n"); |
781 | 0 | } |
782 | | |
783 | | void |
784 | | logging::MsgEntry(const char* aEntryText, ...) |
785 | 0 | { |
786 | 0 | printf(" "); |
787 | 0 |
|
788 | 0 | va_list argptr; |
789 | 0 | va_start(argptr, aEntryText); |
790 | 0 | vprintf(aEntryText, argptr); |
791 | 0 | va_end(argptr); |
792 | 0 |
|
793 | 0 | printf("\n"); |
794 | 0 | } |
795 | | |
796 | | void |
797 | | logging::Text(const char* aText) |
798 | 0 | { |
799 | 0 | printf(" %s\n", aText); |
800 | 0 | } |
801 | | |
802 | | void |
803 | | logging::Address(const char* aDescr, Accessible* aAcc) |
804 | 0 | { |
805 | 0 | if (!aAcc->IsDoc()) { |
806 | 0 | printf(" %s accessible: %p, node: %p\n", aDescr, |
807 | 0 | static_cast<void*>(aAcc), static_cast<void*>(aAcc->GetNode())); |
808 | 0 | } |
809 | 0 |
|
810 | 0 | DocAccessible* doc = aAcc->Document(); |
811 | 0 | nsIDocument* docNode = doc->DocumentNode(); |
812 | 0 | printf(" document: %p, node: %p\n", |
813 | 0 | static_cast<void*>(doc), static_cast<void*>(docNode)); |
814 | 0 |
|
815 | 0 | printf(" "); |
816 | 0 | LogDocURI(docNode); |
817 | 0 | printf("\n"); |
818 | 0 | } |
819 | | |
820 | | void |
821 | | logging::Node(const char* aDescr, nsINode* aNode) |
822 | 0 | { |
823 | 0 | printf(" "); |
824 | 0 |
|
825 | 0 | if (!aNode) { |
826 | 0 | printf("%s: null\n", aDescr); |
827 | 0 | return; |
828 | 0 | } |
829 | 0 | |
830 | 0 | if (aNode->IsDocument()) { |
831 | 0 | printf("%s: %p, document\n", aDescr, static_cast<void*>(aNode)); |
832 | 0 | return; |
833 | 0 | } |
834 | 0 | |
835 | 0 | nsINode* parentNode = aNode->GetParentNode(); |
836 | 0 | int32_t idxInParent = parentNode ? parentNode->ComputeIndexOf(aNode) : - 1; |
837 | 0 |
|
838 | 0 | if (aNode->IsText()) { |
839 | 0 | printf("%s: %p, text node, idx in parent: %d\n", |
840 | 0 | aDescr, static_cast<void*>(aNode), idxInParent); |
841 | 0 | return; |
842 | 0 | } |
843 | 0 | |
844 | 0 | if (!aNode->IsElement()) { |
845 | 0 | printf("%s: %p, not accessible node type, idx in parent: %d\n", |
846 | 0 | aDescr, static_cast<void*>(aNode), idxInParent); |
847 | 0 | return; |
848 | 0 | } |
849 | 0 | |
850 | 0 | dom::Element* elm = aNode->AsElement(); |
851 | 0 |
|
852 | 0 | nsAutoCString tag; |
853 | 0 | elm->NodeInfo()->NameAtom()->ToUTF8String(tag); |
854 | 0 |
|
855 | 0 | nsAtom* idAtom = elm->GetID(); |
856 | 0 | nsAutoCString id; |
857 | 0 | if (idAtom) |
858 | 0 | idAtom->ToUTF8String(id); |
859 | 0 |
|
860 | 0 | printf("%s: %p, %s@id='%s', idx in parent: %d\n", |
861 | 0 | aDescr, static_cast<void*>(elm), tag.get(), id.get(), idxInParent); |
862 | 0 | } |
863 | | |
864 | | void |
865 | | logging::Document(DocAccessible* aDocument) |
866 | 0 | { |
867 | 0 | printf(" Document: %p, document node: %p\n", |
868 | 0 | static_cast<void*>(aDocument), |
869 | 0 | static_cast<void*>(aDocument->DocumentNode())); |
870 | 0 |
|
871 | 0 | printf(" Document "); |
872 | 0 | LogDocURI(aDocument->DocumentNode()); |
873 | 0 | printf("\n"); |
874 | 0 | } |
875 | | |
876 | | void |
877 | | logging::AccessibleInfo(const char* aDescr, Accessible* aAccessible) |
878 | 0 | { |
879 | 0 | printf(" %s: %p; ", aDescr, static_cast<void*>(aAccessible)); |
880 | 0 | if (!aAccessible) { |
881 | 0 | printf("\n"); |
882 | 0 | return; |
883 | 0 | } |
884 | 0 | if (aAccessible->IsDefunct()) { |
885 | 0 | printf("defunct\n"); |
886 | 0 | return; |
887 | 0 | } |
888 | 0 | if (!aAccessible->Document() || aAccessible->Document()->IsDefunct()) { |
889 | 0 | printf("document is shutting down, no info\n"); |
890 | 0 | return; |
891 | 0 | } |
892 | 0 | |
893 | 0 | nsAutoString role; |
894 | 0 | GetAccService()->GetStringRole(aAccessible->Role(), role); |
895 | 0 | printf("role: %s", NS_ConvertUTF16toUTF8(role).get()); |
896 | 0 |
|
897 | 0 | nsAutoString name; |
898 | 0 | aAccessible->Name(name); |
899 | 0 | if (!name.IsEmpty()) { |
900 | 0 | printf(", name: '%s'", NS_ConvertUTF16toUTF8(name).get()); |
901 | 0 | } |
902 | 0 |
|
903 | 0 | printf(", idx: %d", aAccessible->IndexInParent()); |
904 | 0 |
|
905 | 0 | nsINode* node = aAccessible->GetNode(); |
906 | 0 | if (!node) { |
907 | 0 | printf(", node: null\n"); |
908 | 0 | } |
909 | 0 | else if (node->IsDocument()) { |
910 | 0 | printf(", document node: %p\n", static_cast<void*>(node)); |
911 | 0 | } |
912 | 0 | else if (node->IsText()) { |
913 | 0 | printf(", text node: %p\n", static_cast<void*>(node)); |
914 | 0 | } |
915 | 0 | else if (node->IsElement()) { |
916 | 0 | dom::Element* el = node->AsElement(); |
917 | 0 |
|
918 | 0 | nsAutoCString tag; |
919 | 0 | el->NodeInfo()->NameAtom()->ToUTF8String(tag); |
920 | 0 |
|
921 | 0 | nsAtom* idAtom = el->GetID(); |
922 | 0 | nsAutoCString id; |
923 | 0 | if (idAtom) { |
924 | 0 | idAtom->ToUTF8String(id); |
925 | 0 | } |
926 | 0 |
|
927 | 0 | printf(", element node: %p, %s@id='%s'\n", |
928 | 0 | static_cast<void*>(el), tag.get(), id.get()); |
929 | 0 | } |
930 | 0 | } |
931 | | |
932 | | void |
933 | | logging::AccessibleNNode(const char* aDescr, Accessible* aAccessible) |
934 | 0 | { |
935 | 0 | printf(" %s: %p; ", aDescr, static_cast<void*>(aAccessible)); |
936 | 0 | if (!aAccessible) |
937 | 0 | return; |
938 | 0 | |
939 | 0 | nsAutoString role; |
940 | 0 | GetAccService()->GetStringRole(aAccessible->Role(), role); |
941 | 0 | nsAutoString name; |
942 | 0 | aAccessible->Name(name); |
943 | 0 |
|
944 | 0 | printf("role: %s, name: '%s';\n", NS_ConvertUTF16toUTF8(role).get(), |
945 | 0 | NS_ConvertUTF16toUTF8(name).get()); |
946 | 0 |
|
947 | 0 | nsAutoCString nodeDescr(aDescr); |
948 | 0 | nodeDescr.AppendLiteral(" node"); |
949 | 0 | Node(nodeDescr.get(), aAccessible->GetNode()); |
950 | 0 |
|
951 | 0 | Document(aAccessible->Document()); |
952 | 0 | } |
953 | | |
954 | | void |
955 | | logging::AccessibleNNode(const char* aDescr, nsINode* aNode) |
956 | 0 | { |
957 | 0 | DocAccessible* document = |
958 | 0 | GetAccService()->GetDocAccessible(aNode->OwnerDoc()); |
959 | 0 |
|
960 | 0 | if (document) { |
961 | 0 | Accessible* accessible = document->GetAccessible(aNode); |
962 | 0 | if (accessible) { |
963 | 0 | AccessibleNNode(aDescr, accessible); |
964 | 0 | return; |
965 | 0 | } |
966 | 0 | } |
967 | 0 | |
968 | 0 | nsAutoCString nodeDescr("[not accessible] "); |
969 | 0 | nodeDescr.Append(aDescr); |
970 | 0 | Node(nodeDescr.get(), aNode); |
971 | 0 |
|
972 | 0 | if (document) { |
973 | 0 | Document(document); |
974 | 0 | return; |
975 | 0 | } |
976 | 0 | |
977 | 0 | printf(" [contained by not accessible document]:\n"); |
978 | 0 | LogDocInfo(aNode->OwnerDoc(), document); |
979 | 0 | printf("\n"); |
980 | 0 | } |
981 | | |
982 | | void |
983 | | logging::DOMEvent(const char* aDescr, nsINode* aOrigTarget, |
984 | | const nsAString& aEventType) |
985 | 0 | { |
986 | 0 | logging::MsgBegin("DOMEvents", "event '%s' %s", |
987 | 0 | NS_ConvertUTF16toUTF8(aEventType).get(), aDescr); |
988 | 0 | logging::AccessibleNNode("Target", aOrigTarget); |
989 | 0 | logging::MsgEnd(); |
990 | 0 | } |
991 | | |
992 | | void |
993 | | logging::Stack() |
994 | 0 | { |
995 | 0 | if (IsEnabled(eStack)) { |
996 | 0 | printf(" stack: \n"); |
997 | 0 | nsTraceRefcnt::WalkTheStack(stdout); |
998 | 0 | } |
999 | 0 | } |
1000 | | |
1001 | | //////////////////////////////////////////////////////////////////////////////// |
1002 | | // namespace logging:: initialization |
1003 | | |
1004 | | bool |
1005 | | logging::IsEnabled(uint32_t aModules) |
1006 | 0 | { |
1007 | 0 | return sModules & aModules; |
1008 | 0 | } |
1009 | | |
1010 | | bool |
1011 | | logging::IsEnabledAll(uint32_t aModules) |
1012 | 0 | { |
1013 | 0 | return (sModules & aModules) == aModules; |
1014 | 0 | } |
1015 | | |
1016 | | bool |
1017 | | logging::IsEnabled(const nsAString& aModuleStr) |
1018 | 0 | { |
1019 | 0 | for (unsigned int idx = 0; idx < ArrayLength(sModuleMap); idx++) { |
1020 | 0 | if (aModuleStr.EqualsASCII(sModuleMap[idx].mStr)) |
1021 | 0 | return sModules & sModuleMap[idx].mModule; |
1022 | 0 | } |
1023 | 0 |
|
1024 | 0 | return false; |
1025 | 0 | } |
1026 | | |
1027 | | void |
1028 | | logging::Enable(const nsCString& aModules) |
1029 | 0 | { |
1030 | 0 | EnableLogging(aModules.get()); |
1031 | 0 | } |
1032 | | |
1033 | | |
1034 | | void |
1035 | | logging::CheckEnv() |
1036 | 0 | { |
1037 | 0 | EnableLogging(PR_GetEnv("A11YLOG")); |
1038 | 0 | } |