Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bindings/core/v8/ToV8.h" | 5 #include "bindings/core/v8/ToV8.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/WindowProxy.h" | 7 #include "bindings/core/v8/WindowProxy.h" |
| 8 #include "core/events/EventTarget.h" | 8 #include "core/events/EventTarget.h" |
| 9 #include "core/frame/DOMWindow.h" | 9 #include "core/frame/DOMWindow.h" |
| 10 #include "core/frame/Frame.h" | 10 #include "core/frame/Frame.h" |
| 11 #include "core/frame/Location.h" | |
| 11 | 12 |
| 12 namespace blink { | 13 namespace blink { |
| 13 | 14 |
| 14 v8::Local<v8::Value> ToV8(DOMWindow* window, | 15 v8::Local<v8::Value> ToV8(DOMWindow* window, |
| 15 v8::Local<v8::Object> creationContext, | 16 v8::Local<v8::Object> creationContext, |
| 16 v8::Isolate* isolate) { | 17 v8::Isolate* isolate) { |
| 17 // Notice that we explicitly ignore creationContext because the DOMWindow | 18 // Notice that we explicitly ignore creationContext because the DOMWindow |
| 18 // has its own creationContext. | 19 // has its own creationContext. |
| 19 | 20 |
| 20 if (UNLIKELY(!window)) | 21 if (UNLIKELY(!window)) |
| 21 return v8::Null(isolate); | 22 return v8::Null(isolate); |
| 22 // Initializes environment of a frame, and return the global object | 23 // Initializes environment of a frame, and return the global object |
| 23 // of the frame. | 24 // of the frame. |
| 24 Frame* frame = window->frame(); | 25 Frame* frame = window->frame(); |
| 25 if (!frame) | 26 if (!frame) |
| 26 return v8Undefined(); | 27 return v8Undefined(); |
| 27 | 28 |
| 28 return frame->windowProxy(DOMWrapperWorld::current(isolate)) | 29 return frame->windowProxy(DOMWrapperWorld::current(isolate)) |
| 29 ->globalIfNotDetached(); | 30 ->globalIfNotDetached(); |
| 30 } | 31 } |
| 31 | 32 |
| 33 v8::Local<v8::Value> ToV8(Location* location, | |
| 34 v8::Local<v8::Object> creationContext, | |
| 35 v8::Isolate* isolate) { | |
| 36 // https://whatwg.org/C/browsers.html#crossorigingetownpropertyhelper-(-o,-p-) | |
| 37 // | |
| 38 // If e.[[NeedsGet]] is true, then set crossOriginGet to an anonymous | |
| 39 // built-in function, created in the current Realm Record, that performs the | |
| 40 // same steps as the getter of the IDL attribute P on object O. | |
| 41 // | |
| 42 // Thus, the returned object should be created in the current Realm Record as | |
| 43 // well, so ignore creationContext and use the current context as the creation | |
| 44 // context. | |
| 45 // | |
| 46 // TODO(dcheng): Is it possible for v8 to just always return the current | |
| 47 // context as the creation context of a remote context's global proxy? | |
| 48 | |
| 49 if (UNLIKELY(!location)) | |
| 50 return v8::Null(isolate); | |
| 51 | |
| 52 v8::Local<v8::Value> wrapper = DOMDataStore::getWrapper(location, isolate); | |
| 53 if (!wrapper.IsEmpty()) | |
| 54 return wrapper; | |
| 55 | |
| 56 wrapper = location->wrap(isolate, isolate->GetCurrentContext()->Global()); | |
| 57 DCHECK(!wrapper.IsEmpty()); | |
| 58 return wrapper; | |
| 59 } | |
|
dcheng
2017/01/19 23:34:07
Modifying ToV8 was my original approach, but it ha
| |
| 60 | |
| 32 v8::Local<v8::Value> ToV8(EventTarget* impl, | 61 v8::Local<v8::Value> ToV8(EventTarget* impl, |
| 33 v8::Local<v8::Object> creationContext, | 62 v8::Local<v8::Object> creationContext, |
| 34 v8::Isolate* isolate) { | 63 v8::Isolate* isolate) { |
| 35 if (UNLIKELY(!impl)) | 64 if (UNLIKELY(!impl)) |
| 36 return v8::Null(isolate); | 65 return v8::Null(isolate); |
| 37 | 66 |
| 38 if (impl->interfaceName() == EventTargetNames::DOMWindow) | 67 if (impl->interfaceName() == EventTargetNames::DOMWindow) |
| 39 return ToV8(static_cast<DOMWindow*>(impl), creationContext, isolate); | 68 return ToV8(static_cast<DOMWindow*>(impl), creationContext, isolate); |
| 40 return ToV8(static_cast<ScriptWrappable*>(impl), creationContext, isolate); | 69 return ToV8(static_cast<ScriptWrappable*>(impl), creationContext, isolate); |
| 41 } | 70 } |
| 42 | 71 |
| 43 } // namespace blink | 72 } // namespace blink |
| OLD | NEW |