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

Side by Side Diff: Source/bindings/v8/custom/V8CustomEventCustom.cpp

Issue 19457002: Make 'any'-typed attributes of events available in isolated worlds (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Patch for landing Created 7 years, 5 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 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. 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 16 matching lines...) Expand all
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 30
31 #include "config.h" 31 #include "config.h"
32 #include "V8CustomEvent.h" 32 #include "V8CustomEvent.h"
33 33
34 #include "V8Event.h" 34 #include "V8Event.h"
35 #include "bindings/v8/Dictionary.h" 35 #include "bindings/v8/Dictionary.h"
36 #include "bindings/v8/ScriptState.h" 36 #include "bindings/v8/ScriptState.h"
37 #include "bindings/v8/ScriptValue.h" 37 #include "bindings/v8/SerializedScriptValue.h"
38 #include "bindings/v8/V8Binding.h" 38 #include "bindings/v8/V8Binding.h"
39 #include "bindings/v8/V8DOMWrapper.h" 39 #include "bindings/v8/V8DOMWrapper.h"
40 #include "bindings/v8/V8HiddenPropertyName.h" 40 #include "bindings/v8/V8HiddenPropertyName.h"
41 #include "core/dom/ContextFeatures.h" 41 #include "core/dom/ContextFeatures.h"
42 #include "core/dom/ExceptionCode.h" 42 #include "core/dom/ExceptionCode.h"
43 #include "core/page/Frame.h" 43 #include "core/page/Frame.h"
44 #include "RuntimeEnabledFeatures.h" 44 #include "RuntimeEnabledFeatures.h"
45 45
46 namespace WebCore { 46 namespace WebCore {
47 47
48 static v8::Handle<v8::Value> cacheState(v8::Handle<v8::Object> customEvent, v8:: Handle<v8::Value> detail) 48 static v8::Handle<v8::Value> cacheState(v8::Handle<v8::Object> customEvent, v8:: Handle<v8::Value> detail)
49 { 49 {
50 customEvent->SetHiddenValue(V8HiddenPropertyName::detail(), detail); 50 customEvent->SetHiddenValue(V8HiddenPropertyName::detail(), detail);
51 return detail; 51 return detail;
52 } 52 }
53 53
54 54
55 void V8CustomEvent::detailAttrGetterCustom(v8::Local<v8::String> name, const v8: :PropertyCallbackInfo<v8::Value>& info) 55 void V8CustomEvent::detailAttrGetterCustom(v8::Local<v8::String> name, const v8: :PropertyCallbackInfo<v8::Value>& info)
56 { 56 {
57 CustomEvent* event = V8CustomEvent::toNative(info.Holder()); 57 CustomEvent* event = V8CustomEvent::toNative(info.Holder());
58 58
59 v8::Handle<v8::Value> result = info.Holder()->GetHiddenValue(V8HiddenPropert yName::detail()); 59 v8::Handle<v8::Value> result = info.Holder()->GetHiddenValue(V8HiddenPropert yName::detail());
60 60
61 if (!result.IsEmpty()) { 61 if (!result.IsEmpty()) {
62 v8SetReturnValue(info, result); 62 v8SetReturnValue(info, result);
63 return; 63 return;
64 } 64 }
65 65
66 SerializedScriptValue* serialized = event->serializedScriptValue(); 66 if (!event->serializedScriptValue()) {
67 if (serialized) { 67 // If we're in an isolated world and the event was created in the main w orld,
68 result = serialized->deserialize(); 68 // we need to find the 'detail' property on the main world wrapper and c lone it.
69 v8::Local<v8::Value> mainWorldDetail = getHiddenValueFromMainWorldWrappe r(info.GetIsolate(), event, V8HiddenPropertyName::detail());
70 if (!mainWorldDetail.IsEmpty())
71 event->setSerializedDetail(SerializedScriptValue::createAndSwallowEx ceptions(mainWorldDetail, info.GetIsolate()));
72 }
73
74 if (event->serializedScriptValue()) {
75 result = event->serializedScriptValue()->deserialize();
69 v8SetReturnValue(info, cacheState(info.Holder(), result)); 76 v8SetReturnValue(info, cacheState(info.Holder(), result));
70 return; 77 return;
71 } 78 }
72 79
73 v8SetReturnValue(info, cacheState(info.Holder(), v8::Null(info.GetIsolate()) )); 80 v8SetReturnValue(info, cacheState(info.Holder(), v8::Null(info.GetIsolate()) ));
74 } 81 }
75 82
76 void V8CustomEvent::initCustomEventMethodCustom(const v8::FunctionCallbackInfo<v 8::Value>& args) 83 void V8CustomEvent::initCustomEventMethodCustom(const v8::FunctionCallbackInfo<v 8::Value>& args)
77 { 84 {
78 CustomEvent* event = V8CustomEvent::toNative(args.Holder()); 85 CustomEvent* event = V8CustomEvent::toNative(args.Holder());
79 ASSERT(!event->serializedScriptValue()); 86 ASSERT(!event->serializedScriptValue());
80 87
81 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, typeArg, args[0]); 88 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, typeArg, args[0]);
82 V8TRYCATCH_VOID(bool, canBubbleArg, args[1]->BooleanValue()); 89 V8TRYCATCH_VOID(bool, canBubbleArg, args[1]->BooleanValue());
83 V8TRYCATCH_VOID(bool, cancelableArg, args[2]->BooleanValue()); 90 V8TRYCATCH_VOID(bool, cancelableArg, args[2]->BooleanValue());
84 v8::Handle<v8::Value> detailsArg = args[3]; 91 v8::Handle<v8::Value> detailsArg = args[3];
85 92
86 args.Holder()->SetHiddenValue(V8HiddenPropertyName::detail(), detailsArg);
87 event->initEvent(typeArg, canBubbleArg, cancelableArg); 93 event->initEvent(typeArg, canBubbleArg, cancelableArg);
94
95 if (!detailsArg.IsEmpty()) {
96 args.Holder()->SetHiddenValue(V8HiddenPropertyName::detail(), detailsArg );
97 if (isolatedWorldForIsolate(args.GetIsolate()))
98 event->setSerializedDetail(SerializedScriptValue::createAndSwallowEx ceptions(detailsArg, args.GetIsolate()));
99 }
88 } 100 }
89 101
90 } // namespace WebCore 102 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698