OLD | NEW |
(Empty) | |
| 1 // Copyright 2011, Google Inc. |
| 2 // All rights reserved. |
| 3 // |
| 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are |
| 6 // met: |
| 7 // |
| 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above |
| 11 // copyright notice, this list of conditions and the following disclaimer |
| 12 // in the documentation and/or other materials provided with the |
| 13 // distribution. |
| 14 // * Neither the name of Google Inc. nor the names of its |
| 15 // contributors may be used to endorse or promote products derived from |
| 16 // this software without specific prior written permission. |
| 17 // |
| 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 |
| 30 #include "config.h" |
| 31 #include "DartDOMWrapper.h" |
| 32 |
| 33 #include "CSSMutableStyleDeclaration.h" |
| 34 #include "DartCSSStyleDeclaration.h" |
| 35 #include "DartDOMCoreException.h" |
| 36 #include "DartEventException.h" |
| 37 #include "DartHTMLElement.h" |
| 38 #include "DartNode.h" |
| 39 #include "DartRangeException.h" |
| 40 #include "DartUtilities.h" |
| 41 #include "DartXMLHttpRequestException.h" |
| 42 #include "DartXPathException.h" |
| 43 #include "HTMLFormControlElement.h" |
| 44 #include <stdio.h> |
| 45 #include <wtf/text/WTFString.h> |
| 46 |
| 47 #if ENABLE(SVG) |
| 48 #include "DartSVGException.h" |
| 49 #endif |
| 50 #if ENABLE(XPATH) |
| 51 #include "DartXPathException.h" |
| 52 #endif |
| 53 #if ENABLE(SQL_DATABASE) |
| 54 #include "DartSQLException.h" |
| 55 #endif |
| 56 #if ENABLE(BLOB) || ENABLE(FILE_SYSTEM) |
| 57 #include "DartFileException.h" |
| 58 #include "DartOperationNotAllowedException.h" |
| 59 #endif |
| 60 #if ENABLE(INDEXED_DATABASE) |
| 61 #include "DartIDBDatabaseException.h" |
| 62 #endif |
| 63 |
| 64 namespace WebCore { |
| 65 |
| 66 void DartDOMWrapper::derefDOMObject(Dart_Handle wrapper, void* domObject) |
| 67 { |
| 68 ASSERT(domObject == readNativePointer(wrapper, kNativeImplementationIndex)); |
| 69 DerefObjectFunction derefObjectFunction = reinterpret_cast<DerefObjectFuncti
on>(readNativePointer(wrapper, kDerefObjectFunctionIndex)); |
| 70 (*derefObjectFunction)(domObject); |
| 71 } |
| 72 |
| 73 Dart_Handle DartDOMWrapper::instantiateWrapper(const char* className) |
| 74 { |
| 75 // FIXME: this all is very ugly, but we're blocked by API here. |
| 76 // In this case we need an API to invoke ctor, or even better, |
| 77 // create an instance without exposing constructor at all. |
| 78 String factoryMethodName = String("_create") + className; |
| 79 Dart_Handle dom = Dart_LookupLibrary(Dart_NewString(DartUtilities::domLibrar
yName)); |
| 80 ASSERT(!Dart_IsError(dom)); |
| 81 |
| 82 Dart_Handle instance = Dart_InvokeStatic(dom, Dart_NewString(className), Dar
tUtilities::stringToDartString(factoryMethodName), 0, 0); |
| 83 ASSERT(!Dart_IsError(instance)); |
| 84 return instance; |
| 85 } |
| 86 |
| 87 bool DartDOMWrapper::instanceOf(const char* dartImplementationClassName, Dart_Ha
ndle wrapper, Dart_Handle& exception) |
| 88 { |
| 89 // FIXME: Cache classes in the corresponding bindings class. Requires persis
tent handles. |
| 90 Dart_Handle dom = DartUtilities::domLibraryForCurrentIsolate(); |
| 91 Dart_Handle cls = Dart_GetClass(dom, Dart_NewString(dartImplementationClassN
ame)); |
| 92 if (Dart_IsError(cls)) { |
| 93 exception = Dart_NewString(Dart_GetError(cls)); |
| 94 return false; |
| 95 } |
| 96 |
| 97 bool isInstanceOf = false; |
| 98 Dart_Handle result = Dart_ObjectIsType(wrapper, cls, &isInstanceOf); |
| 99 if (Dart_IsError(result)) { |
| 100 exception = Dart_NewString(Dart_GetError(result)); |
| 101 return false; |
| 102 } |
| 103 if (!isInstanceOf) { |
| 104 String message = String("Invalid class: expected ") + dartImplementation
ClassName; |
| 105 exception = DartUtilities::stringToDartString(message); |
| 106 return false; |
| 107 } |
| 108 |
| 109 return true; |
| 110 } |
| 111 |
| 112 Dart_Handle DartDOMWrapper::exceptionCodeToDartException(ExceptionCode exception
Code) |
| 113 { |
| 114 ASSERT(exceptionCode > 0); |
| 115 |
| 116 ExceptionCodeDescription description(exceptionCode); |
| 117 |
| 118 switch (description.type) { |
| 119 case DOMCoreExceptionType: |
| 120 return toDartValue(DOMCoreException::create(description)); |
| 121 case RangeExceptionType: |
| 122 return toDartValue(RangeException::create(description)); |
| 123 case EventExceptionType: |
| 124 return toDartValue(EventException::create(description)); |
| 125 case XMLHttpRequestExceptionType: |
| 126 return toDartValue(XMLHttpRequestException::create(description)); |
| 127 #if ENABLE(SVG) |
| 128 case SVGExceptionType: |
| 129 return toDartValue(SVGException::create(description)); |
| 130 #endif |
| 131 case XPathExceptionType: |
| 132 return toDartValue(XPathException::create(description)); |
| 133 #if ENABLE(SQL_DATABASE) |
| 134 case SQLExceptionType: |
| 135 return toDartValue(SQLException::create(description)); |
| 136 #endif |
| 137 #if ENABLE(BLOB) || ENABLE(FILE_SYSTEM) |
| 138 case FileExceptionType: |
| 139 return toDartValue(FileException::create(description)); |
| 140 case OperationNotAllowedExceptionType: |
| 141 return toDartValue(OperationNotAllowedException::create(description)); |
| 142 #endif |
| 143 #if ENABLE(INDEXED_DATABASE) |
| 144 case IDBDatabaseExceptionType: |
| 145 return toDartValue(IDBDatabaseException::create(description)); |
| 146 #endif |
| 147 } |
| 148 |
| 149 ASSERT_NOT_REACHED(); |
| 150 return Dart_NewString("Unknown WebCore exception"); |
| 151 } |
| 152 |
| 153 Dart_Handle toDartValue(ContainerNode* value) |
| 154 { |
| 155 return toDartValue(static_cast<Node*>(value)); |
| 156 } |
| 157 |
| 158 Dart_Handle toDartValue(CSSMutableStyleDeclaration* value) |
| 159 { |
| 160 return toDartValue(static_cast<CSSStyleDeclaration*>(value)); |
| 161 } |
| 162 |
| 163 Dart_Handle toDartValue(HTMLFormControlElement* value) |
| 164 { |
| 165 return toDartValue(static_cast<HTMLElement*>(value)); |
| 166 } |
| 167 |
| 168 Dart_Handle toDartValue(NPObject* object) |
| 169 { |
| 170 // FIXME: put NPObjects into a map as well. |
| 171 return DartDOMWrapper::newWrapper("NPObject", object); |
| 172 } |
| 173 |
| 174 } |
OLD | NEW |