|
1 /** |
|
2 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) |
|
3 * |
|
4 * This library is free software; you can redistribute it and/or |
|
5 * modify it under the terms of the GNU Library General Public |
|
6 * License as published by the Free Software Foundation; either |
|
7 * version 2 of the License, or (at your option) any later version. |
|
8 * |
|
9 * This library is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12 * Library General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Library General Public License |
|
15 * along with this library; see the file COPYING.LIB. If not, write to |
|
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
17 * Boston, MA 02110-1301, USA. |
|
18 * |
|
19 */ |
|
20 |
|
21 #include "config.h" |
|
22 |
|
23 #if ENABLE(WML) |
|
24 #include "WMLErrorHandling.h" |
|
25 |
|
26 #include "Console.h" |
|
27 #include "Frame.h" |
|
28 #include "Document.h" |
|
29 #include "DOMWindow.h" |
|
30 #include "XMLDocumentParser.h" |
|
31 #include <wtf/text/CString.h> |
|
32 |
|
33 namespace WebCore { |
|
34 |
|
35 void reportWMLError(Document* doc, WMLErrorCode error) |
|
36 { |
|
37 if (!doc || error == WMLErrorUnknown) |
|
38 return; |
|
39 |
|
40 String errorMessage = errorMessageForErrorCode(error); |
|
41 XMLDocumentParser* parser = static_cast<XMLDocumentParser*>(doc->parser()); |
|
42 if (parser && error != WMLErrorDeckNotAccessible) { |
|
43 // Some errors are reported as result of an insertedIntoDocument() call. |
|
44 // If this happened, parsing has been stopped, and the document fragment |
|
45 // is wrapped in a XHTML error document. That means insertedIntoDocument() |
|
46 // will be called again - do NOT report the error twice, that would result |
|
47 // in an infinite error reporting loop. |
|
48 if (!parser->wellFormed()) |
|
49 return; |
|
50 |
|
51 parser->handleError(XMLDocumentParser::fatal, errorMessage.latin1().data(), parser->lineNumber(), parser->columnNumber()); |
|
52 } else { |
|
53 Frame* frame = doc->frame(); |
|
54 if (!frame) |
|
55 return; |
|
56 |
|
57 DOMWindow* domWindow = frame->domWindow(); |
|
58 if (!domWindow) |
|
59 return; |
|
60 |
|
61 Console* console = domWindow->console(); |
|
62 if (!console) |
|
63 return; |
|
64 |
|
65 console->addMessage(WMLMessageSource, LogMessageType, ErrorMessageLevel, errorMessage, 0, String()); |
|
66 } |
|
67 } |
|
68 |
|
69 String errorMessageForErrorCode(WMLErrorCode error) |
|
70 { |
|
71 switch (error) { |
|
72 case WMLErrorConflictingEventBinding: |
|
73 return "Conflicting event bindings within an element."; |
|
74 case WMLErrorDeckNotAccessible: |
|
75 return "Deck not accessible."; |
|
76 case WMLErrorDuplicatedDoElement: |
|
77 return "At least two do elements share a name, which is not allowed."; |
|
78 case WMLErrorForbiddenTaskInAnchorElement: |
|
79 return "Forbidden task contained in anchor element."; |
|
80 case WMLErrorInvalidColumnsNumberInTable: |
|
81 return "A table contains an invalid number of columns."; |
|
82 case WMLErrorInvalidVariableName: |
|
83 return "A variable name contains invalid characters."; |
|
84 case WMLErrorInvalidVariableReference: |
|
85 return "A variable reference uses invalid syntax."; |
|
86 case WMLErrorInvalidVariableReferenceLocation: |
|
87 return "A variable reference is placed in an invalid location."; |
|
88 case WMLErrorMultipleAccessElements: |
|
89 return "Only one access element is allowed in a deck."; |
|
90 case WMLErrorMultipleTemplateElements: |
|
91 return "Only one template element is allowed in a deck."; |
|
92 case WMLErrorNoCardInDocument: |
|
93 return "No card contained in document."; |
|
94 case WMLErrorMultipleTimerElements: |
|
95 return "Only one timer element is allowed in a card."; |
|
96 case WMLErrorUnknown: |
|
97 return String(); |
|
98 }; |
|
99 |
|
100 ASSERT_NOT_REACHED(); |
|
101 return String(); |
|
102 } |
|
103 |
|
104 } |
|
105 |
|
106 #endif |