OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009, 2011 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 27 matching lines...) Expand all Loading... | |
38 #include "core/frame/DOMWindow.h" | 38 #include "core/frame/DOMWindow.h" |
39 #include "core/frame/Frame.h" | 39 #include "core/frame/Frame.h" |
40 #include "v8/include/v8.h" | 40 #include "v8/include/v8.h" |
41 #include "wtf/Assertions.h" | 41 #include "wtf/Assertions.h" |
42 | 42 |
43 namespace blink { | 43 namespace blink { |
44 | 44 |
45 WindowProxy::~WindowProxy() { | 45 WindowProxy::~WindowProxy() { |
46 // clearForClose() or clearForNavigation() must be invoked before destruction | 46 // clearForClose() or clearForNavigation() must be invoked before destruction |
47 // starts. | 47 // starts. |
48 DCHECK(m_lifecycle != Lifecycle::ContextInitialized); | 48 DCHECK(m_lifecycle != Lifecycle::ContextIsInitialized); |
49 } | 49 } |
50 | 50 |
51 DEFINE_TRACE(WindowProxy) { | 51 DEFINE_TRACE(WindowProxy) { |
52 visitor->trace(m_frame); | 52 visitor->trace(m_frame); |
53 } | 53 } |
54 | 54 |
55 WindowProxy::WindowProxy(v8::Isolate* isolate, | 55 WindowProxy::WindowProxy(v8::Isolate* isolate, |
56 Frame& frame, | 56 Frame& frame, |
57 RefPtr<DOMWrapperWorld> world) | 57 RefPtr<DOMWrapperWorld> world) |
58 : m_isolate(isolate), | 58 : m_isolate(isolate), |
59 m_frame(frame), | 59 m_frame(frame), |
60 | 60 |
61 m_world(std::move(world)), | 61 m_world(std::move(world)), |
62 m_lifecycle(Lifecycle::ContextUninitialized) {} | 62 m_lifecycle(Lifecycle::ContextIsUninitialized) {} |
63 | 63 |
64 void WindowProxy::clearForClose() { | 64 void WindowProxy::clearForClose() { |
65 disposeContext(DoNotDetachGlobal); | 65 disposeContext(DoNotDetachGlobal); |
66 } | 66 } |
67 | 67 |
68 void WindowProxy::clearForNavigation() { | 68 void WindowProxy::clearForNavigation() { |
69 disposeContext(DetachGlobal); | 69 disposeContext(DetachGlobal); |
70 } | 70 } |
71 | 71 |
72 v8::Local<v8::Object> WindowProxy::globalIfNotDetached() { | 72 v8::Local<v8::Object> WindowProxy::globalIfNotDetached() { |
73 if (m_lifecycle == Lifecycle::ContextInitialized) { | 73 if (m_lifecycle == Lifecycle::ContextIsInitialized) { |
74 DLOG_IF(FATAL, !m_isGlobalObjectAttached) | 74 DLOG_IF(FATAL, !m_isGlobalObjectAttached) |
75 << "Context is initialized but global object is detached!"; | 75 << "Context is initialized but global object is detached!"; |
76 return m_globalProxy.newLocal(m_isolate); | 76 return m_globalProxy.newLocal(m_isolate); |
77 } | 77 } |
78 return v8::Local<v8::Object>(); | 78 return v8::Local<v8::Object>(); |
79 } | 79 } |
80 | 80 |
81 v8::Local<v8::Object> WindowProxy::releaseGlobal() { | 81 v8::Local<v8::Object> WindowProxy::releaseGlobal() { |
82 DCHECK(m_lifecycle != Lifecycle::ContextInitialized); | 82 DCHECK(m_lifecycle != Lifecycle::ContextIsInitialized); |
83 | 83 |
84 // Make sure the global object was detached from the proxy by calling | 84 // Make sure the global object was detached from the proxy by calling |
85 // clearForNavigation(). | 85 // clearForNavigation(). |
86 DLOG_IF(FATAL, m_isGlobalObjectAttached) | 86 DLOG_IF(FATAL, m_isGlobalObjectAttached) |
87 << "Context not detached by calling clearForNavigation()"; | 87 << "Context not detached by calling clearForNavigation()"; |
88 | 88 |
89 v8::Local<v8::Object> global = m_globalProxy.newLocal(m_isolate); | 89 v8::Local<v8::Object> global = m_globalProxy.newLocal(m_isolate); |
90 m_globalProxy.clear(); | 90 m_globalProxy.clear(); |
91 return global; | 91 return global; |
92 } | 92 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 // has a security token which is the domain. The outer window cannot | 133 // has a security token which is the domain. The outer window cannot |
134 // have its own properties. window.foo = 'x' is delegated to the | 134 // have its own properties. window.foo = 'x' is delegated to the |
135 // inner window. | 135 // inner window. |
136 // | 136 // |
137 // When a frame navigates to a new page, the inner window is cut off | 137 // When a frame navigates to a new page, the inner window is cut off |
138 // the outer window, and the outer window identify is preserved for | 138 // the outer window, and the outer window identify is preserved for |
139 // the frame. However, a new inner window is created for the new page. | 139 // the frame. However, a new inner window is created for the new page. |
140 // If there are JS code holds a closure to the old inner window, | 140 // If there are JS code holds a closure to the old inner window, |
141 // it won't be able to reach the outer window via its global object. | 141 // it won't be able to reach the outer window via its global object. |
142 void WindowProxy::initializeIfNeeded() { | 142 void WindowProxy::initializeIfNeeded() { |
143 // TODO(haraken): It is wrong to re-initialize an already detached window | 143 if (m_lifecycle == Lifecycle::ContextIsUninitialized || |
144 // proxy. This must be 'if(m_lifecycle == Lifecycle::ContextUninitialized)'. | 144 m_lifecycle == Lifecycle::GlobalObjectIsDetached) { |
dcheng
2017/03/30 21:03:01
I wonder how often we actually take advantage of t
Yuki
2017/03/31 07:32:09
Yes, I'll address this point separately.
As I qui
| |
145 if (m_lifecycle != Lifecycle::ContextInitialized) { | |
146 initialize(); | 145 initialize(); |
147 } | 146 } |
148 } | 147 } |
149 | 148 |
150 v8::Local<v8::Object> WindowProxy::associateWithWrapper( | 149 v8::Local<v8::Object> WindowProxy::associateWithWrapper( |
151 DOMWindow* window, | 150 DOMWindow* window, |
152 const WrapperTypeInfo* wrapperTypeInfo, | 151 const WrapperTypeInfo* wrapperTypeInfo, |
153 v8::Local<v8::Object> wrapper) { | 152 v8::Local<v8::Object> wrapper) { |
154 if (m_world->domDataStore().set(m_isolate, window, wrapperTypeInfo, | 153 if (m_world->domDataStore().set(m_isolate, window, wrapperTypeInfo, |
155 wrapper)) { | 154 wrapper)) { |
156 wrapperTypeInfo->wrapperCreated(); | 155 wrapperTypeInfo->wrapperCreated(); |
157 V8DOMWrapper::setNativeInfo(m_isolate, wrapper, wrapperTypeInfo, window); | 156 V8DOMWrapper::setNativeInfo(m_isolate, wrapper, wrapperTypeInfo, window); |
158 DCHECK(V8DOMWrapper::hasInternalFieldsSet(wrapper)); | 157 DCHECK(V8DOMWrapper::hasInternalFieldsSet(wrapper)); |
159 } | 158 } |
160 SECURITY_CHECK(toScriptWrappable(wrapper) == window); | 159 SECURITY_CHECK(toScriptWrappable(wrapper) == window); |
161 return wrapper; | 160 return wrapper; |
162 } | 161 } |
163 | 162 |
164 } // namespace blink | 163 } // namespace blink |
OLD | NEW |