| 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 "DartClassInfo.h" | |
| 32 | |
| 33 #include "DartController.h" | |
| 34 #include "DartDOMWindow.h" | |
| 35 #include "DartDOMWrapper.h" | |
| 36 #include "DartIsolateState.h" | |
| 37 #include "DartUtilities.h" | |
| 38 #include "PlatformString.h" | |
| 39 #include "npruntime_impl.h" | |
| 40 | |
| 41 #include <bindings/npruntime.h> | |
| 42 #include <dart_api.h> | |
| 43 #include <wtf/HashMap.h> | |
| 44 #include <wtf/OwnArrayPtr.h> | |
| 45 #include <wtf/StdLibExtras.h> | |
| 46 #include <wtf/text/CString.h> | |
| 47 #include <wtf/text/StringHash.h> | |
| 48 | |
| 49 namespace WebCore { | |
| 50 | |
| 51 static void topLevelWindow(Dart_NativeArguments args) | |
| 52 { | |
| 53 DartApiScope dartApiScope; | |
| 54 if (!DartUtilities::isFullDomIsolate(Dart_CurrentIsolate())) | |
| 55 Dart_ThrowException(DartUtilities::domDisabledException()); | |
| 56 | |
| 57 // Return full DOMWindow implementation (toDartValue(DOMWindow*) always retu
rns secure wrapper). | |
| 58 Dart_Handle result = DartDOMWrapper::toDart<DartDOMWindow>(DartUtilities::do
mWindowForCurrentIsolate()); | |
| 59 if (result) | |
| 60 Dart_SetReturnValue(args, result); | |
| 61 } | |
| 62 | |
| 63 static void npObjectRetrieve(Dart_NativeArguments args) | |
| 64 { | |
| 65 DartApiScope dartApiScope; | |
| 66 Dart_Handle exception; | |
| 67 { | |
| 68 const ParameterAdapter<String> key(Dart_GetNativeArgument(args, 0)); | |
| 69 if (!key.conversionSuccessful()) { | |
| 70 exception = key.exception(); | |
| 71 goto fail; | |
| 72 } | |
| 73 | |
| 74 DartController* controller = DartController::retrieve(DartUtilities::scr
iptExecutionContext()); | |
| 75 NPObject* npObject = controller->npObject(key); | |
| 76 if (npObject) | |
| 77 Dart_SetReturnValue(args, toDartValue(npObject)); | |
| 78 return; | |
| 79 } | |
| 80 | |
| 81 fail: | |
| 82 Dart_ThrowException(exception); | |
| 83 ASSERT_NOT_REACHED(); | |
| 84 } | |
| 85 | |
| 86 static void npObjectProperty(Dart_NativeArguments args) | |
| 87 { | |
| 88 DART_UNIMPLEMENTED(); | |
| 89 } | |
| 90 | |
| 91 static NPIdentifier getStringIdentifier(Dart_Handle id) | |
| 92 { | |
| 93 intptr_t length = 0; | |
| 94 // FIXME: add return value check. | |
| 95 Dart_StringLength(id, &length); | |
| 96 char* buffer = new char[length + 1]; | |
| 97 Dart_StringGet8(id, reinterpret_cast<uint8_t*>(buffer), &length); | |
| 98 buffer[length] = '\0'; | |
| 99 NPIdentifier result = _NPN_GetStringIdentifier(buffer); | |
| 100 delete [] buffer; | |
| 101 return result; | |
| 102 } | |
| 103 | |
| 104 static void npObjectInvoke(Dart_NativeArguments args) | |
| 105 { | |
| 106 DartApiScope dartApiScope; | |
| 107 Dart_Handle exception; | |
| 108 { | |
| 109 NPObject* npObject = DartDOMWrapper::receiver< NPObject >(args); | |
| 110 | |
| 111 if (!Dart_IsNull(Dart_GetNativeArgument(args, 2))) { | |
| 112 exception = DartUtilities::notImplementedException(); | |
| 113 goto fail; | |
| 114 } | |
| 115 | |
| 116 // FIXME: proper support for HTMLAppletElement and HTMLEmbedElement, see
v8. | |
| 117 | |
| 118 // FIXME: support argument conversion. | |
| 119 int numArgs = 0; | |
| 120 OwnArrayPtr<NPVariant> npArgs = adoptArrayPtr(new NPVariant[numArgs]); | |
| 121 | |
| 122 NPVariant result; | |
| 123 VOID_TO_NPVARIANT(result); | |
| 124 | |
| 125 bool retval = true; | |
| 126 if (npObject->_class->invoke) { | |
| 127 NPIdentifier identifier = getStringIdentifier(Dart_GetNativeArgument
(args, 1)); | |
| 128 retval = npObject->_class->invoke(npObject, identifier, npArgs.get()
, numArgs, &result); | |
| 129 } | |
| 130 | |
| 131 if (!retval) { | |
| 132 exception = Dart_NewString("Error calling method on NPObject."); | |
| 133 goto fail; | |
| 134 } | |
| 135 | |
| 136 // FIXME: support return value conversion. | |
| 137 | |
| 138 return; | |
| 139 } | |
| 140 | |
| 141 fail: | |
| 142 Dart_ThrowException(exception); | |
| 143 ASSERT_NOT_REACHED(); | |
| 144 } | |
| 145 | |
| 146 static void spawnDomIsolate(Dart_NativeArguments args) | |
| 147 { | |
| 148 DartApiScope dartApiScope; | |
| 149 Dart_Handle exception; | |
| 150 { | |
| 151 // IMPORTANT NOTE: Runtime type of first argument must be checked | |
| 152 // by Dart code---we're doing read without any additional checks here! | |
| 153 intptr_t value; | |
| 154 Dart_Handle result = Dart_GetNativeInstanceField(Dart_GetNativeArgument(
args, 0), 0, &value); | |
| 155 ASSERT(!Dart_IsError(result)); | |
| 156 UNUSED_PARAM(result); | |
| 157 RefPtr<DOMWindow> targetWindow(reinterpret_cast<DOMWindow*>(value)); | |
| 158 | |
| 159 const ParameterAdapter< String > entryPoint(Dart_GetNativeArgument(args,
1)); | |
| 160 if (!entryPoint.conversionSuccessful()) { | |
| 161 exception = entryPoint.exception(); | |
| 162 goto fail; | |
| 163 } | |
| 164 | |
| 165 ScriptExecutionContext* context = DartUtilities::scriptExecutionContext(
); | |
| 166 if (!context) { | |
| 167 exception = DartUtilities::internalErrorException("[spawnDomIsolate]
failed to retrieve ScriptExecutionContext"); | |
| 168 goto fail; | |
| 169 } | |
| 170 | |
| 171 DartController* controller = DartController::retrieve(context); | |
| 172 if (!controller) { | |
| 173 exception = DartUtilities::internalErrorException("[spawnDomIsolate]
failed to retrieve DartController"); | |
| 174 goto fail; | |
| 175 } | |
| 176 | |
| 177 Dart_Handle sendPort = controller->spawnDomIsolate(targetWindow.get(), e
ntryPoint); | |
| 178 if (Dart_IsError(sendPort)) { | |
| 179 exception = DartUtilities::internalErrorException(Dart_GetError(send
Port)); | |
| 180 goto fail; | |
| 181 } | |
| 182 | |
| 183 Dart_SetReturnValue(args, sendPort); | |
| 184 return; | |
| 185 } | |
| 186 | |
| 187 fail: | |
| 188 Dart_ThrowException(exception); | |
| 189 ASSERT_NOT_REACHED(); | |
| 190 } | |
| 191 | |
| 192 namespace DartDOMWindowInternal { | |
| 193 | |
| 194 void historyCrossFrameGetter(Dart_NativeArguments); | |
| 195 | |
| 196 void locationCrossFrameGetter(Dart_NativeArguments); | |
| 197 | |
| 198 } | |
| 199 | |
| 200 extern Dart_NativeFunction snapshotResolver(Dart_Handle name, int argumentCount)
; | |
| 201 | |
| 202 Dart_NativeFunction domResolver(Dart_Handle name, int argumentCount) | |
| 203 { | |
| 204 // Some utility functions. | |
| 205 if (Dart_NativeFunction func = snapshotResolver(name, argumentCount)) | |
| 206 return func; | |
| 207 | |
| 208 String str = DartUtilities::dartStringToString(name); | |
| 209 if (argumentCount == 0 && str == "TopLevel_Window") | |
| 210 return topLevelWindow; | |
| 211 if (argumentCount == 1 && str == "NPObject_retrieve") | |
| 212 return npObjectRetrieve; | |
| 213 if (argumentCount == 2 && str == "NPObject_property") | |
| 214 return npObjectProperty; | |
| 215 if (argumentCount == 3 && str == "NPObject_invoke") | |
| 216 return npObjectInvoke; | |
| 217 if (argumentCount == 1 && str == "DOMWindow_history_cross_frame_Getter") | |
| 218 return DartDOMWindowInternal::historyCrossFrameGetter; | |
| 219 if (argumentCount == 1 && str == "DOMWindow_location_cross_frame_Getter") | |
| 220 return DartDOMWindowInternal::locationCrossFrameGetter; | |
| 221 if (argumentCount == 2 && str == "Utils_spawnDomIsolate") | |
| 222 return spawnDomIsolate; | |
| 223 return 0; | |
| 224 } | |
| 225 | |
| 226 } | |
| OLD | NEW |