Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/LocalWindowProxy.h

Issue 2620313002: Refactor WindowProxy into Local and Remote subclasses. (Closed)
Patch Set: explicit Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(v8::Isolate* isolate,
56 50 LocalFrame& frame,
57 ~WindowProxy(); 51 RefPtr<DOMWrapperWorld> world) {
58 DECLARE_TRACE(); 52 return new LocalWindowProxy(isolate, frame, std::move(world));
59
60 v8::Local<v8::Context> contextIfInitialized() const {
61 return m_scriptState ? m_scriptState->context() : v8::Local<v8::Context>();
62 } 53 }
63 ScriptState* getScriptState() const { return m_scriptState.get(); }
64 54
65 // Update document object of the frame. 55 // Update document object of the frame.
66 void updateDocument(); 56 void updateDocument();
67 57
68 void namedItemAdded(HTMLDocument*, const AtomicString&); 58 void namedItemAdded(HTMLDocument*, const AtomicString&);
69 void namedItemRemoved(HTMLDocument*, const AtomicString&); 59 void namedItemRemoved(HTMLDocument*, const AtomicString&);
70 60
71 // Update the security origin of a document 61 // Update the security origin of a document
72 // (e.g., after setting docoument.domain). 62 // (e.g., after setting docoument.domain).
73 void updateSecurityOrigin(SecurityOrigin*); 63 void updateSecurityOrigin(SecurityOrigin*);
74 64
75 void initializeIfNeeded(); 65 private:
66 LocalWindowProxy(v8::Isolate*, LocalFrame&, RefPtr<DOMWrapperWorld>);
76 67
77 void clearForNavigation(); 68 void initialize() override;
78 void clearForClose(); 69 void disposeContext(GlobalDetachmentBehavior) override;
79 70
80 v8::Local<v8::Object> globalIfNotDetached(); 71 // Creates a new v8::Context with the window wrapper object as the global
81 v8::Local<v8::Object> releaseGlobal(); 72 // object (aka the inner global). Note that the window wrapper and its
82 void setGlobal(v8::Local<v8::Object>); 73 // prototype chain do not get fully initialized yet, e.g. the window
83 74 // wrapper is not yet associated with the native DOMWindow object.
84 DOMWrapperWorld& world() { return *m_world; } 75 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 76
101 void setSecurityToken(SecurityOrigin*); 77 void setSecurityToken(SecurityOrigin*);
102 78
103 // The JavaScript wrapper for the document object is cached on the global 79 // The JavaScript wrapper for the document object is cached on the global
104 // object for fast access. UpdateDocumentProperty sets the wrapper 80 // object for fast access. UpdateDocumentProperty sets the wrapper
105 // for the current document on the global object. 81 // for the current document on the global object.
106 void updateDocumentProperty(); 82 void updateDocumentProperty();
107 83
108 // Updates Activity Logger for the current context. 84 // Updates Activity Logger for the current context.
109 void updateActivityLogger(); 85 void updateActivityLogger();
110 86
111 // Creates a new v8::Context with the window wrapper object as the global 87 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 }; 88 };
128 89
129 } // namespace blink 90 } // namespace blink
130 91
131 #endif // WindowProxy_h 92 #endif // LocalWindowProxy_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/bindings.gni ('k') | third_party/WebKit/Source/bindings/core/v8/LocalWindowProxy.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698