OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 13 matching lines...) Expand all Loading... | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
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 | 30 |
31 #ifndef WindowProxy_h | 31 #ifndef WindowProxy_h |
32 #define WindowProxy_h | 32 #define WindowProxy_h |
33 | 33 |
34 #include <v8.h> | |
34 #include "bindings/core/v8/DOMWrapperWorld.h" | 35 #include "bindings/core/v8/DOMWrapperWorld.h" |
35 #include "bindings/core/v8/ScopedPersistent.h" | 36 #include "bindings/core/v8/ScopedPersistent.h" |
36 #include "bindings/core/v8/ScriptState.h" | 37 #include "core/CoreExport.h" |
37 #include "platform/heap/Handle.h" | 38 #include "platform/heap/Handle.h" |
38 #include "wtf/RefPtr.h" | 39 #include "wtf/RefPtr.h" |
39 #include <v8.h> | |
40 | 40 |
41 namespace blink { | 41 namespace blink { |
42 | 42 |
43 class Frame; | 43 class Frame; |
44 class ScriptController; | |
45 | 44 |
46 // WindowProxy represents all the per-global object state for a Frame that | 45 // WindowProxy represents all the per-global object state for a Frame that |
47 // persist between navigations. | 46 // persist between navigations. |
48 class WindowProxy : public GarbageCollectedFinalized<WindowProxy> { | 47 class WindowProxy : public GarbageCollectedFinalized<WindowProxy> { |
49 public: | 48 public: |
50 virtual ~WindowProxy(); | 49 virtual ~WindowProxy(); |
51 | 50 |
52 DECLARE_TRACE(); | 51 DECLARE_TRACE(); |
53 | 52 |
54 v8::Local<v8::Context> contextIfInitialized() const { | |
55 return m_scriptState ? m_scriptState->context() : v8::Local<v8::Context>(); | |
56 } | |
57 void initializeIfNeeded(); | 53 void initializeIfNeeded(); |
58 | 54 |
59 void clearForClose(); | 55 void clearForClose(); |
60 void clearForNavigation(); | 56 void clearForNavigation(); |
61 | 57 |
62 v8::Local<v8::Object> globalIfNotDetached(); | 58 CORE_EXPORT v8::Local<v8::Object> globalIfNotDetached(); |
63 v8::Local<v8::Object> releaseGlobal(); | 59 v8::Local<v8::Object> releaseGlobal(); |
64 void setGlobal(v8::Local<v8::Object>); | 60 void setGlobal(v8::Local<v8::Object>); |
65 | 61 |
66 // TODO(dcheng): Temporarily exposed to avoid include cycles. Remove the need | 62 // TODO(dcheng): Temporarily exposed to avoid include cycles. Remove the need |
67 // for this and remove this getter. | 63 // for this and remove this getter. |
68 DOMWrapperWorld& world() { return *m_world; } | 64 DOMWrapperWorld& world() { return *m_world; } |
69 | 65 |
70 protected: | 66 protected: |
71 // TODO(dcheng): Remove this friend declaration once LocalWindowProxyManager | |
72 // and ScriptController are merged. | |
73 friend class ScriptController; | |
74 | |
75 // A valid transition is from ContextUninitialized to ContextInitialized, | 67 // A valid transition is from ContextUninitialized to ContextInitialized, |
76 // and then ContextDetached. Other transitions are forbidden. | 68 // and then ContextDetached. Other transitions are forbidden. |
77 enum class Lifecycle { | 69 enum class Lifecycle { |
78 ContextUninitialized, | 70 ContextUninitialized, |
79 ContextInitialized, | 71 ContextInitialized, |
80 ContextDetached, | 72 ContextDetached, |
81 }; | 73 }; |
82 | 74 |
83 WindowProxy(v8::Isolate*, Frame&, RefPtr<DOMWrapperWorld>); | 75 WindowProxy(v8::Isolate*, Frame&, RefPtr<DOMWrapperWorld>); |
84 | 76 |
85 virtual void initialize() = 0; | 77 virtual void initialize() = 0; |
86 | 78 |
87 enum GlobalDetachmentBehavior { DoNotDetachGlobal, DetachGlobal }; | 79 enum GlobalDetachmentBehavior { DoNotDetachGlobal, DetachGlobal }; |
88 virtual void disposeContext(GlobalDetachmentBehavior); | 80 virtual void disposeContext(GlobalDetachmentBehavior) = 0; |
89 | |
90 // Associates the window wrapper and its prototype chain with the native | |
91 // DOMWindow object. Also does some more Window-specific initialization. | |
92 void setupWindowPrototypeChain(); | |
93 | 81 |
94 v8::Isolate* isolate() const { return m_isolate; } | 82 v8::Isolate* isolate() const { return m_isolate; } |
95 Frame* frame() const { return m_frame.get(); } | 83 Frame* frame() const { return m_frame.get(); } |
96 ScriptState* getScriptState() const { return m_scriptState.get(); } | 84 |
85 #if DCHECK_IS_ON() | |
86 void didAttachGlobalProxy() { m_isGlobalProxyDetached = false; } | |
87 void didDetachGlobalProxy() { m_isGlobalProxyDetached = true; } | |
88 #endif | |
97 | 89 |
98 private: | 90 private: |
99 v8::Isolate* const m_isolate; | 91 v8::Isolate* const m_isolate; |
100 const Member<Frame> m_frame; | 92 const Member<Frame> m_frame; |
93 #if DCHECK_IS_ON() | |
94 bool m_isGlobalProxyDetached = true; | |
haraken
2017/02/16 01:11:19
I'd prefer renaming this to m_isGlobalProxyAttache
dcheng
2017/02/16 03:14:07
It is possible to combine this into Lifecycle as w
| |
95 #endif | |
101 | 96 |
102 protected: | 97 protected: |
103 // TODO(dcheng): Move this to LocalWindowProxy once RemoteWindowProxy uses | |
104 // remote contexts. | |
105 RefPtr<ScriptState> m_scriptState; | |
106 // TODO(dcheng): Consider making these private and using getters. | 98 // TODO(dcheng): Consider making these private and using getters. |
107 const RefPtr<DOMWrapperWorld> m_world; | 99 const RefPtr<DOMWrapperWorld> m_world; |
108 ScopedPersistent<v8::Object> m_globalProxy; | 100 ScopedPersistent<v8::Object> m_globalProxy; |
109 Lifecycle m_lifecycle; | 101 Lifecycle m_lifecycle; |
110 }; | 102 }; |
111 | 103 |
112 } // namespace blink | 104 } // namespace blink |
113 | 105 |
114 #endif // WindowProxy_h | 106 #endif // WindowProxy_h |
OLD | NEW |