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 10 matching lines...) Expand all Loading... | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
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 LocalWindowProxy_h |
32 #define WindowProxy_h | 32 #define LocalWindowProxy_h |
33 | 33 |
34 #include "bindings/core/v8/DOMWrapperWorld.h" | 34 #include "bindings/core/v8/DOMWrapperWorld.h" |
35 #include "bindings/core/v8/ScopedPersistent.h" | 35 #include "bindings/core/v8/WindowProxy.h" |
36 #include "bindings/core/v8/ScriptState.h" | 36 #include "core/frame/LocalFrame.h" |
37 #include "platform/heap/Handle.h" | |
38 #include "platform/weborigin/SecurityOrigin.h" | |
39 #include "wtf/HashMap.h" | |
40 #include "wtf/PassRefPtr.h" | |
41 #include "wtf/RefPtr.h" | 37 #include "wtf/RefPtr.h" |
42 #include "wtf/text/AtomicString.h" | 38 #include "wtf/text/AtomicString.h" |
43 #include <v8.h> | 39 #include <v8.h> |
44 | 40 |
45 namespace blink { | 41 namespace blink { |
46 | 42 |
47 class Frame; | |
48 class HTMLDocument; | 43 class HTMLDocument; |
49 class SecurityOrigin; | 44 class SecurityOrigin; |
50 | 45 |
51 // WindowProxy represents all the per-global object state for a Frame that | 46 // Subclass of WindowProxy that only handles LocalFrame. |
52 // persist between navigations. | 47 class LocalWindowProxy final : public WindowProxy { |
53 class WindowProxy final : public GarbageCollectedFinalized<WindowProxy> { | |
54 public: | 48 public: |
55 static WindowProxy* create(v8::Isolate*, Frame*, DOMWrapperWorld&); | 49 static LocalWindowProxy* create(LocalFrame& frame, |
50 v8::Isolate* isolate, | |
51 RefPtr<DOMWrapperWorld> world) { | |
52 return new LocalWindowProxy(frame, isolate, std::move(world)); | |
53 } | |
56 | 54 |
57 ~WindowProxy(); | 55 ~LocalWindowProxy() override; |
Yuki
2017/01/11 10:09:24
nit: "= default" should work. WindowProxy::~Windo
dcheng
2017/01/11 10:35:28
Removed, since that's equivalent to = default.
| |
58 DECLARE_TRACE(); | |
59 | |
60 v8::Local<v8::Context> contextIfInitialized() const { | |
61 return m_scriptState ? m_scriptState->context() : v8::Local<v8::Context>(); | |
62 } | |
63 ScriptState* getScriptState() const { return m_scriptState.get(); } | |
64 | 56 |
65 // Update document object of the frame. | 57 // Update document object of the frame. |
66 void updateDocument(); | 58 void updateDocument(); |
67 | 59 |
68 void namedItemAdded(HTMLDocument*, const AtomicString&); | 60 void namedItemAdded(HTMLDocument*, const AtomicString&); |
69 void namedItemRemoved(HTMLDocument*, const AtomicString&); | 61 void namedItemRemoved(HTMLDocument*, const AtomicString&); |
70 | 62 |
71 // Update the security origin of a document | 63 // Update the security origin of a document |
72 // (e.g., after setting docoument.domain). | 64 // (e.g., after setting docoument.domain). |
73 void updateSecurityOrigin(SecurityOrigin*); | 65 void updateSecurityOrigin(SecurityOrigin*); |
74 | 66 |
75 void initializeIfNeeded(); | 67 private: |
68 LocalWindowProxy(LocalFrame&, v8::Isolate*, RefPtr<DOMWrapperWorld>); | |
76 | 69 |
77 void clearForNavigation(); | 70 void initialize() override; |
78 void clearForClose(); | 71 void disposeContext(GlobalDetachmentBehavior) override; |
79 | 72 |
80 v8::Local<v8::Object> globalIfNotDetached(); | 73 // Creates a new v8::Context with the window wrapper object as the global |
81 v8::Local<v8::Object> releaseGlobal(); | 74 // object (aka the inner global). Note that the window wrapper and its |
82 void setGlobal(v8::Local<v8::Object>); | 75 // prototype chain do not get fully initialized yet, e.g. the window |
83 | 76 // wrapper is not yet associated with the native DOMWindow object. |
84 DOMWrapperWorld& world() { return *m_world; } | 77 void createContext(); |
85 | |
86 private: | |
87 // A valid transition is from ContextUninitialized to ContextInitialized, | |
88 // and then ContextDetached. Other transitions are forbidden. | |
89 enum class Lifecycle { | |
90 ContextUninitialized, | |
91 ContextInitialized, | |
92 ContextDetached, | |
93 }; | |
94 | |
95 WindowProxy(Frame*, PassRefPtr<DOMWrapperWorld>, v8::Isolate*); | |
96 void initialize(); | |
97 | |
98 enum GlobalDetachmentBehavior { DoNotDetachGlobal, DetachGlobal }; | |
99 void disposeContext(GlobalDetachmentBehavior); | |
100 | 78 |
101 void setSecurityToken(SecurityOrigin*); | 79 void setSecurityToken(SecurityOrigin*); |
102 | 80 |
103 // The JavaScript wrapper for the document object is cached on the global | 81 // The JavaScript wrapper for the document object is cached on the global |
104 // object for fast access. UpdateDocumentProperty sets the wrapper | 82 // object for fast access. UpdateDocumentProperty sets the wrapper |
105 // for the current document on the global object. | 83 // for the current document on the global object. |
106 void updateDocumentProperty(); | 84 void updateDocumentProperty(); |
107 | 85 |
108 // Updates Activity Logger for the current context. | 86 // Updates Activity Logger for the current context. |
109 void updateActivityLogger(); | 87 void updateActivityLogger(); |
110 | 88 |
111 // Creates a new v8::Context with the window wrapper object as the global | 89 LocalFrame* frame() const { return toLocalFrame(WindowProxy::frame()); } |
112 // object (aka the inner global). Note that the window wrapper and its | |
113 // prototype chain do not get fully initialized yet, e.g. the window | |
114 // wrapper is not yet associated with the native DOMWindow object. | |
115 void createContext(); | |
116 | |
117 // Associates the window wrapper and its prototype chain with the native | |
118 // DOMWindow object. Also does some more Window-specific initialization. | |
119 void setupWindowPrototypeChain(); | |
120 | |
121 Member<Frame> m_frame; | |
122 v8::Isolate* m_isolate; | |
123 RefPtr<ScriptState> m_scriptState; | |
124 RefPtr<DOMWrapperWorld> m_world; | |
125 ScopedPersistent<v8::Object> m_globalProxy; | |
126 Lifecycle m_lifecycle; | |
127 }; | 90 }; |
128 | 91 |
129 } // namespace blink | 92 } // namespace blink |
130 | 93 |
131 #endif // WindowProxy_h | 94 #endif // LocalWindowProxy_h |
OLD | NEW |