Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: Source/bindings/dart/DartNativeUtilities.cpp

Issue 24677002: Revert "Revert "Dartium changes for custom element lifecycle events."" (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012, Google Inc. 1 // Copyright 2012, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 15 matching lines...) Expand all
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30 #include "config.h" 30 #include "config.h"
31 #include "bindings/dart/DartNativeUtilities.h" 31 #include "bindings/dart/DartNativeUtilities.h"
32 32
33 #include "DartDOMData.h" 33 #include "DartDOMData.h"
34 #include "DartDOMStringMap.h" 34 #include "DartDOMStringMap.h"
35 #include "DartDocument.h" 35 #include "DartDocument.h"
36 #include "DartElement.h"
36 #include "DartWindow.h" 37 #include "DartWindow.h"
37 #include "RuntimeEnabledFeatures.h" 38 #include "RuntimeEnabledFeatures.h"
38 #include "bindings/dart/DartController.h" 39 #include "bindings/dart/DartController.h"
40 #include "bindings/dart/DartCustomElementConstructorBuilder.h"
41 #include "bindings/dart/DartCustomElementLifecycleCallbacks.h"
39 #include "bindings/dart/DartDOMWrapper.h" 42 #include "bindings/dart/DartDOMWrapper.h"
40 #include "bindings/dart/DartUtilities.h" 43 #include "bindings/dart/DartUtilities.h"
41 #include "bindings/dart/V8Converter.h" 44 #include "bindings/dart/V8Converter.h"
42 #include "bindings/v8/ScriptController.h" 45 #include "bindings/v8/ScriptController.h"
43 #include "bindings/v8/npruntime_impl.h" 46 #include "bindings/v8/npruntime_impl.h"
47 #include "core/dom/CustomElementCallbackDispatcher.h"
48 #include "core/dom/Document.h"
44 #include "core/page/Frame.h" 49 #include "core/page/Frame.h"
45 50
46 #include <bindings/npruntime.h> 51 #include <bindings/npruntime.h>
47 #include <dart_api.h> 52 #include <dart_api.h>
48 #include <wtf/HashMap.h> 53 #include <wtf/HashMap.h>
49 #include <wtf/OwnArrayPtr.h> 54 #include <wtf/OwnArrayPtr.h>
50 #include <wtf/StdLibExtras.h> 55 #include <wtf/StdLibExtras.h>
51 #include <wtf/text/CString.h> 56 #include <wtf/text/CString.h>
52 #include <wtf/text/StringHash.h> 57 #include <wtf/text/StringHash.h>
53 58
54 namespace WebCore { 59 namespace WebCore {
55 60
61 namespace DartNativeUtilitiesInternal {
62
56 static void topLevelWindow(Dart_NativeArguments args) 63 static void topLevelWindow(Dart_NativeArguments args)
57 { 64 {
58 // Return full DOMWindow implementation (DartDOMWrapper::createWrapper alway s returns a secure wrapper). 65 // Return full DOMWindow implementation (DartDOMWrapper::createWrapper alway s returns a secure wrapper).
59 DOMWindow* window = DartUtilities::domWindowForCurrentIsolate(); 66 DOMWindow* window = DartUtilities::domWindowForCurrentIsolate();
60 DartDOMWrapper::returnToDart<DartWindow>(args, window); 67 DartDOMWrapper::returnToDart<DartWindow>(args, window);
61 } 68 }
62 69
63 /** 70 /**
64 * Gadget for testing. 71 * Gadget for testing.
65 * 72 *
(...skipping 26 matching lines...) Expand all
92 { 99 {
93 static int isolateId = 0; 100 static int isolateId = 0;
94 Dart_SetReturnValue(args, DartUtilities::intToDart(isolateId++)); 101 Dart_SetReturnValue(args, DartUtilities::intToDart(isolateId++));
95 } 102 }
96 103
97 static void registerElement(Dart_NativeArguments args) 104 static void registerElement(Dart_NativeArguments args)
98 { 105 {
99 DartApiScope dartApiScope; 106 DartApiScope dartApiScope;
100 Dart_Handle exception = 0; 107 Dart_Handle exception = 0;
101 { 108 {
102 DartStringAdapter tag = DartUtilities::dartToString(Dart_GetNativeArgume nt(args, 0), exception); 109 ScriptExecutionContext* scriptExecutionContext = DartUtilities::scriptEx ecutionContext();
110 ASSERT(scriptExecutionContext);
111
112 Document* document = DartDocument::toNative(args, 0, exception);
103 if (exception) 113 if (exception)
104 goto fail; 114 goto fail;
105 115
106 Dart_Handle customType = Dart_GetNativeArgument(args, 1); 116 DartStringAdapter name = DartUtilities::dartToString(Dart_GetNativeArgum ent(args, 1), exception);
117 if (exception)
118 goto fail;
119
120 Dart_Handle customType = Dart_GetNativeArgument(args, 2);
107 ASSERT(Dart_IsType(customType)); 121 ASSERT(Dart_IsType(customType));
108 122
109 Dart_Handle nativeType = Dart_GetNativeArgument(args, 2); 123 AtomicString extendsTagName;
110 ASSERT(Dart_IsType(nativeType)); 124 Dart_Handle extendsArg = Dart_GetNativeArgument(args, 3);
125 if (!Dart_IsNull(extendsArg)) {
126 extendsTagName = DartUtilities::dartToString(extendsArg, exception);
127 if (exception) {
128 goto fail;
129 }
130 }
111 131
112 DartCustomElementMap* map = DartDOMData::current()->customElementMap(); 132 CustomElementRegistrationContext* registrationContext = document->regist rationContext();
113 if (map->contains(tag)) { 133 if (!registrationContext) {
114 // FIXME: Wrap in a proper exception. 134 exception = DartDOMWrapper::exceptionCodeToDartException(NotSupporte dError);
115 exception = Dart_NewStringFromCString("Element tag already registere d");
116 goto fail; 135 goto fail;
117 } 136 }
118 map->set(tag, Dart_NewPersistentHandle(customType));
119 137
120 DartCustomElementMap* baseMap = DartDOMData::current()->customBaseElemen tMap(); 138 ScriptState* scriptState = ScriptState::forContext(DartUtilities::curren tV8Context());
121 baseMap->set(tag, Dart_NewPersistentHandle(nativeType)); 139
140 const Dictionary dictionary;
141 DartCustomElementConstructorBuilder constructorBuilder(customType, exten dsTagName, scriptState, &dictionary);
142 DartExceptionState es;
143 registrationContext->registerElement(document, &constructorBuilder, name , CustomElement::AllNames, es);
144 if (es.hadException()) {
145 exception = DartDOMWrapper::exceptionCodeToDartException(es);
146 goto fail;
147 }
122 return; 148 return;
123 } 149 }
124 150
151 fail:
152 Dart_ThrowException(exception);
153 ASSERT_NOT_REACHED();
154 }
155
156 void createElement(Dart_NativeArguments args)
157 {
158 Dart_Handle exception = 0;
159 {
160 Document* receiver = DartDOMWrapper::receiver< Document >(args);
161
162 DartStringAdapter localName = DartUtilities::dartToString(args, 1, excep tion);
163 if (exception)
164 goto fail;
165
166 DartExceptionState es;
167 RefPtr<Element> result;
168 {
169 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope ;
170
171 result = receiver->createElement(localName, es);
172 }
173 DartElement::returnToDart(args, result);
174 if (es.hadException()) {
175 exception = DartDOMWrapper::exceptionCodeToDartException(es);
176 goto fail;
177 }
178 return;
179 }
180
125 fail: 181 fail:
126 Dart_ThrowException(exception); 182 Dart_ThrowException(exception);
127 ASSERT_NOT_REACHED(); 183 ASSERT_NOT_REACHED();
128 } 184 }
129 185
130 static void npObjectRetrieve(Dart_NativeArguments args) 186 static void npObjectRetrieve(Dart_NativeArguments args)
131 { 187 {
132 Dart_Handle exception = 0; 188 Dart_Handle exception = 0;
133 { 189 {
134 DartStringAdapter key = DartUtilities::dartToString(Dart_GetNativeArgume nt(args, 0), exception); 190 DartStringAdapter key = DartUtilities::dartToString(Dart_GetNativeArgume nt(args, 0), exception);
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 406
351 context->postTask(adoptPtr(new SpawnDomUriTask(targetUrl.string().ascii( ).data(), portId))); 407 context->postTask(adoptPtr(new SpawnDomUriTask(targetUrl.string().ascii( ).data(), portId)));
352 return; 408 return;
353 } 409 }
354 410
355 fail: 411 fail:
356 Dart_ThrowException(exception); 412 Dart_ThrowException(exception);
357 ASSERT_NOT_REACHED(); 413 ASSERT_NOT_REACHED();
358 } 414 }
359 415
416 } // namespace DartNativeUtilitiesInternal
417
360 namespace DartWindowInternal { 418 namespace DartWindowInternal {
361 419
362 void historyCrossFrameGetter(Dart_NativeArguments); 420 void historyCrossFrameGetter(Dart_NativeArguments);
363 421
364 void locationCrossFrameGetter(Dart_NativeArguments); 422 void locationCrossFrameGetter(Dart_NativeArguments);
365 423
366 } 424 }
367 425
368 extern Dart_NativeFunction htmlSnapshotResolver(Dart_Handle name, int argumentCo unt); 426 extern Dart_NativeFunction htmlSnapshotResolver(Dart_Handle name, int argumentCo unt);
369 427
370 Dart_NativeFunction commonHtmlResolver(Dart_Handle name, int argumentCount) 428 Dart_NativeFunction commonHtmlResolver(Dart_Handle name, int argumentCount)
371 { 429 {
372 String str = DartUtilities::toString(name); 430 String str = DartUtilities::toString(name);
373 if (argumentCount == 2 && str == "Utils_spawnDomFunction") 431 if (argumentCount == 2 && str == "Utils_spawnDomFunction")
374 return spawnDomFunction; 432 return DartNativeUtilitiesInternal::spawnDomFunction;
375 if (argumentCount == 2 && str == "Utils_spawnDomUri") 433 if (argumentCount == 2 && str == "Utils_spawnDomUri")
376 return spawnDomUri; 434 return DartNativeUtilitiesInternal::spawnDomUri;
377 return 0; 435 return 0;
378 } 436 }
379 437
380 Dart_NativeFunction domIsolateHtmlResolver(Dart_Handle name, int argumentCount) 438 Dart_NativeFunction domIsolateHtmlResolver(Dart_Handle name, int argumentCount)
381 { 439 {
382 // Some utility functions. 440 // Some utility functions.
383 if (Dart_NativeFunction func = commonHtmlResolver(name, argumentCount)) 441 if (Dart_NativeFunction func = commonHtmlResolver(name, argumentCount))
384 return func; 442 return func;
385 if (Dart_NativeFunction func = htmlSnapshotResolver(name, argumentCount)) 443 if (Dart_NativeFunction func = htmlSnapshotResolver(name, argumentCount))
386 return func; 444 return func;
387 if (Dart_NativeFunction func = DartDOMStringMap::resolver(name, argumentCoun t)) 445 if (Dart_NativeFunction func = DartDOMStringMap::resolver(name, argumentCoun t))
388 return func; 446 return func;
389 447
390 String str = DartUtilities::toString(name); 448 String str = DartUtilities::toString(name);
391 if (argumentCount == 0 && str == "Utils_window") 449 if (argumentCount == 0 && str == "Utils_window")
392 return topLevelWindow; 450 return DartNativeUtilitiesInternal::topLevelWindow;
393 if (argumentCount == 1 && str == "Utils_forwardingPrint") 451 if (argumentCount == 1 && str == "Utils_forwardingPrint")
394 return forwardingPrint; 452 return DartNativeUtilitiesInternal::forwardingPrint;
395 if (argumentCount == 0 && str == "Utils_getNewIsolateId") 453 if (argumentCount == 0 && str == "Utils_getNewIsolateId")
396 return getNewIsolateId; 454 return DartNativeUtilitiesInternal::getNewIsolateId;
397 if (argumentCount == 3 && str == "Utils_register") 455 if (argumentCount == 4 && str == "Utils_register")
398 return registerElement; 456 return DartNativeUtilitiesInternal::registerElement;
457 if (argumentCount == 2 && str == "Utils_createElement")
458 return DartNativeUtilitiesInternal::createElement;
399 if (argumentCount == 1 && str == "NPObject_retrieve") 459 if (argumentCount == 1 && str == "NPObject_retrieve")
400 return npObjectRetrieve; 460 return DartNativeUtilitiesInternal::npObjectRetrieve;
401 if (argumentCount == 2 && str == "NPObject_property") 461 if (argumentCount == 2 && str == "NPObject_property")
402 return npObjectProperty; 462 return DartNativeUtilitiesInternal::npObjectProperty;
403 if (argumentCount == 3 && str == "NPObject_invoke") 463 if (argumentCount == 3 && str == "NPObject_invoke")
404 return npObjectInvoke; 464 return DartNativeUtilitiesInternal::npObjectInvoke;
405 if (argumentCount == 1 && str == "Window_history_cross_frame_Getter") 465 if (argumentCount == 1 && str == "Window_history_cross_frame_Getter")
406 return DartWindowInternal::historyCrossFrameGetter; 466 return DartWindowInternal::historyCrossFrameGetter;
407 if (argumentCount == 1 && str == "Window_location_cross_frame_Getter") 467 if (argumentCount == 1 && str == "Window_location_cross_frame_Getter")
408 return DartWindowInternal::locationCrossFrameGetter; 468 return DartWindowInternal::locationCrossFrameGetter;
409 return 0; 469 return 0;
410 } 470 }
411 471
412 } 472 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698