Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef DOMWindow_h | 5 #ifndef DOMWindow_h |
| 6 #define DOMWindow_h | 6 #define DOMWindow_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/Transferables.h" | 8 #include "bindings/core/v8/Transferables.h" |
| 9 #include "core/CoreExport.h" | 9 #include "core/CoreExport.h" |
| 10 #include "core/events/EventTarget.h" | 10 #include "core/events/EventTarget.h" |
| 11 #include "core/frame/DOMWindowBase64.h" | 11 #include "core/frame/DOMWindowBase64.h" |
| 12 #include "core/frame/Frame.h" | 12 #include "core/frame/Frame.h" |
| 13 #include "platform/heap/Handle.h" | 13 #include "platform/heap/Handle.h" |
| 14 #include "wtf/Assertions.h" | 14 #include "wtf/Assertions.h" |
| 15 #include "wtf/Forward.h" | 15 #include "wtf/Forward.h" |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 | 18 |
| 19 class Document; | 19 class Document; |
| 20 class InputDeviceCapabilitiesConstants; | 20 class InputDeviceCapabilitiesConstants; |
| 21 class LocalDOMWindow; | |
| 21 class Location; | 22 class Location; |
| 22 class LocalDOMWindow; | |
| 23 class MessageEvent; | 23 class MessageEvent; |
| 24 class SerializedScriptValue; | 24 class SerializedScriptValue; |
| 25 class WindowProxyManager; | |
| 25 | 26 |
| 26 class CORE_EXPORT DOMWindow : public EventTargetWithInlineData, | 27 class CORE_EXPORT DOMWindow : public EventTargetWithInlineData, |
| 27 public DOMWindowBase64 { | 28 public DOMWindowBase64 { |
| 28 DEFINE_WRAPPERTYPEINFO(); | 29 DEFINE_WRAPPERTYPEINFO(); |
| 29 | 30 |
| 30 public: | 31 public: |
| 31 ~DOMWindow() override; | 32 ~DOMWindow() override; |
| 32 | 33 |
| 33 Frame* frame() const { | 34 Frame* frame() const { |
| 34 // A Frame is typically reused for navigations. If |m_frame| is not null, | 35 // A Frame is typically reused for navigations. If |m_frame| is not null, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 | 102 |
| 102 // FIXME: When this DOMWindow is no longer the active DOMWindow (i.e., | 103 // FIXME: When this DOMWindow is no longer the active DOMWindow (i.e., |
| 103 // when its document is no longer the document that is displayed in its | 104 // when its document is no longer the document that is displayed in its |
| 104 // frame), we would like to zero out m_frame to avoid being confused | 105 // frame), we would like to zero out m_frame to avoid being confused |
| 105 // by the document that is currently active in m_frame. | 106 // by the document that is currently active in m_frame. |
| 106 // See https://bugs.webkit.org/show_bug.cgi?id=62054 | 107 // See https://bugs.webkit.org/show_bug.cgi?id=62054 |
| 107 bool isCurrentlyDisplayedInFrame() const; | 108 bool isCurrentlyDisplayedInFrame() const; |
| 108 | 109 |
| 109 bool isSecureContext() const; | 110 bool isSecureContext() const; |
| 110 | 111 |
| 112 v8::Local<v8::Object> globalProxy(DOMWrapperWorld&); | |
| 113 | |
| 111 InputDeviceCapabilitiesConstants* getInputDeviceCapabilities(); | 114 InputDeviceCapabilitiesConstants* getInputDeviceCapabilities(); |
| 112 | 115 |
| 113 protected: | 116 protected: |
| 114 explicit DOMWindow(Frame&); | 117 explicit DOMWindow(Frame&); |
| 115 | 118 |
| 116 virtual void schedulePostMessage(MessageEvent*, | 119 virtual void schedulePostMessage(MessageEvent*, |
| 117 PassRefPtr<SecurityOrigin> target, | 120 PassRefPtr<SecurityOrigin> target, |
| 118 Document* source) = 0; | 121 Document* source) = 0; |
| 119 | 122 |
| 120 void disconnectFromFrame() { m_frame = nullptr; } | 123 void disconnectFromFrame() { m_frame = nullptr; } |
| 121 | 124 |
| 122 private: | 125 private: |
| 123 Member<Frame> m_frame; | 126 Member<Frame> m_frame; |
| 127 // Unlike |m_frame|, |m_windowProxyManager| is available even after the | |
| 128 // window's frame gets detached from the DOM, until the end of the lifetime | |
| 129 // of this object. | |
|
haraken
2017/04/06 17:25:27
I don't fully understand why DOMWindow needs to ho
dcheng
2017/04/07 06:23:12
Right now it does, but maybe it shouldn't. Accordi
Yuki
2017/04/07 08:40:19
My understanding is that we agreed that we need to
| |
| 130 // | |
| 131 // Note that |m_windowProxyManager| is always available despite of WeakMember | |
| 132 // because this window object is unreachable when |m_windowProxyManager| gets | |
| 133 // collected. | |
| 134 // - |m_windowProxyManager| is unreachable. | |
| 135 // - All WindowProxies in |m_windowProxyManager| are unreachable. | |
| 136 // - One of the WindowProxies is the WindowProxy for this window object, and | |
| 137 // it's unreachable. | |
| 138 // - So, this window object is unreachable, too. | |
| 139 // Thus, if this window object is reachable, |m_windowProxyManager| is still | |
| 140 // available. | |
|
dcheng
2017/04/07 18:48:48
Thinking about this more, I wonder if this is guar
Yuki
2017/04/10 09:43:32
You're right. Let me change the approach overall.
| |
| 141 // | |
| 142 // The reason why we cannot make |m_windowProxyManager| non-weak Member is | |
| 143 // because WindowProxy has |m_globalProxy| as a ScopedPersistent. We need | |
|
haraken
2017/04/06 17:25:27
Can we break the cycle by replacing the ScopedPers
Yuki
2017/04/07 08:40:19
I don't fully understand this point and I'm nore s
haraken
2017/04/07 10:08:58
Ah, makes sense.
However, I don't fully understan
Yuki
2017/04/07 10:30:44
We have another case: iframe is detacehd from the
| |
| 144 // the following steps in order to collect the window object. | |
| 145 // 1. Blink GC collects |m_windowProxyManager| and its WindowProxies. | |
| 146 // 2. WindowProxy's |m_globalProxy| (v8::Persistent) is destroyed. | |
| 147 // Note that |m_globalProxy| had a strong reference to the global proxy. | |
| 148 // 3. V8 GC collects the global proxy, global object, and context. | |
| 149 // Note that the global proxy and global object had strong references to | |
| 150 // this DOMWindow object. | |
| 151 // 4. Blink GC collects this window object. | |
| 152 // Non-weak Member makes a cycle between Blink GC and V8 GC and currently | |
| 153 // the two GC systems cannot detect it as collectable. | |
| 154 const WeakMember<WindowProxyManager> m_windowProxyManager; | |
| 124 Member<InputDeviceCapabilitiesConstants> m_inputCapabilities; | 155 Member<InputDeviceCapabilitiesConstants> m_inputCapabilities; |
| 125 mutable Member<Location> m_location; | 156 mutable Member<Location> m_location; |
| 126 | 157 |
| 127 // Set to true when close() has been called. Needed for | 158 // Set to true when close() has been called. Needed for |
| 128 // |window.closed| determinism; having it return 'true' | 159 // |window.closed| determinism; having it return 'true' |
| 129 // only after the layout widget's deferred window close | 160 // only after the layout widget's deferred window close |
| 130 // operation has been performed, exposes (confusing) | 161 // operation has been performed, exposes (confusing) |
| 131 // implementation details to scripts. | 162 // implementation details to scripts. |
| 132 bool m_windowIsClosing; | 163 bool m_windowIsClosing; |
| 133 | 164 |
| 134 }; | 165 }; |
| 135 | 166 |
| 136 } // namespace blink | 167 } // namespace blink |
| 137 | 168 |
| 138 #endif // DOMWindow_h | 169 #endif // DOMWindow_h |
| OLD | NEW |