Chromium Code Reviews| 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 17 matching lines...) Expand all Loading... | |
| 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 "bindings/core/v8/DOMWrapperWorld.h" | 34 #include "bindings/core/v8/DOMWrapperWorld.h" |
| 35 #include "bindings/core/v8/ScopedPersistent.h" | 35 #include "bindings/core/v8/ScopedPersistent.h" |
| 36 #include "bindings/core/v8/ScriptState.h" | 36 #include "bindings/core/v8/ScriptState.h" |
| 37 #include "platform/heap/Handle.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" | 38 #include "wtf/RefPtr.h" |
| 42 #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; | 43 class Frame; |
| 48 class HTMLDocument; | 44 class ScriptController; |
| 49 class SecurityOrigin; | |
| 50 | 45 |
| 51 // WindowProxy represents all the per-global object state for a Frame that | 46 // WindowProxy represents all the per-global object state for a Frame that |
| 52 // persist between navigations. | 47 // persist between navigations. |
| 53 class WindowProxy final : public GarbageCollectedFinalized<WindowProxy> { | 48 class WindowProxy : public GarbageCollectedFinalized<WindowProxy> { |
| 54 public: | 49 public: |
| 55 static WindowProxy* create(v8::Isolate*, Frame*, DOMWrapperWorld&); | 50 virtual ~WindowProxy(); |
| 56 | 51 |
| 57 ~WindowProxy(); | |
| 58 DECLARE_TRACE(); | 52 DECLARE_TRACE(); |
| 59 | 53 |
| 60 v8::Local<v8::Context> contextIfInitialized() const { | 54 v8::Local<v8::Context> contextIfInitialized() const { |
| 61 return m_scriptState ? m_scriptState->context() : v8::Local<v8::Context>(); | 55 return m_scriptState ? m_scriptState->context() : v8::Local<v8::Context>(); |
| 62 } | 56 } |
| 63 ScriptState* getScriptState() const { return m_scriptState.get(); } | |
| 64 | |
| 65 // Update document object of the frame. | |
| 66 void updateDocument(); | |
| 67 | |
| 68 void namedItemAdded(HTMLDocument*, const AtomicString&); | |
| 69 void namedItemRemoved(HTMLDocument*, const AtomicString&); | |
| 70 | |
| 71 // Update the security origin of a document | |
| 72 // (e.g., after setting docoument.domain). | |
| 73 void updateSecurityOrigin(SecurityOrigin*); | |
| 74 | |
| 75 void initializeIfNeeded(); | 57 void initializeIfNeeded(); |
| 76 | 58 |
| 59 void clearForClose(); | |
| 77 void clearForNavigation(); | 60 void clearForNavigation(); |
| 78 void clearForClose(); | |
| 79 | 61 |
| 80 v8::Local<v8::Object> globalIfNotDetached(); | 62 v8::Local<v8::Object> globalIfNotDetached(); |
| 81 v8::Local<v8::Object> releaseGlobal(); | 63 v8::Local<v8::Object> releaseGlobal(); |
| 82 void setGlobal(v8::Local<v8::Object>); | 64 void setGlobal(v8::Local<v8::Object>); |
| 83 | 65 |
| 66 // TODO(dcheng): Temporarily exposed to avoid include cycles. Remove the need | |
| 67 // for this and remove this getter. | |
| 84 DOMWrapperWorld& world() { return *m_world; } | 68 DOMWrapperWorld& world() { return *m_world; } |
| 85 | 69 |
| 86 private: | 70 protected: |
| 71 // TODO(dcheng): Remove this friend declaration once LocalWindowProxyManager | |
| 72 // and ScriptController are merged. | |
| 73 friend class ScriptController; | |
| 74 | |
| 87 // A valid transition is from ContextUninitialized to ContextInitialized, | 75 // A valid transition is from ContextUninitialized to ContextInitialized, |
| 88 // and then ContextDetached. Other transitions are forbidden. | 76 // and then ContextDetached. Other transitions are forbidden. |
| 89 enum class Lifecycle { | 77 enum class Lifecycle { |
| 90 ContextUninitialized, | 78 ContextUninitialized, |
| 91 ContextInitialized, | 79 ContextInitialized, |
| 92 ContextDetached, | 80 ContextDetached, |
| 93 }; | 81 }; |
| 94 | 82 |
| 95 WindowProxy(Frame*, PassRefPtr<DOMWrapperWorld>, v8::Isolate*); | 83 WindowProxy(Frame&, v8::Isolate*, RefPtr<DOMWrapperWorld>); |
|
Yuki
2017/01/11 10:09:24
nit: Could you put v8::Isolate* first as it's our
dcheng
2017/01/11 10:35:29
Done, here and elsewhere.
| |
| 96 void initialize(); | 84 |
| 85 virtual void initialize() = 0; | |
| 97 | 86 |
| 98 enum GlobalDetachmentBehavior { DoNotDetachGlobal, DetachGlobal }; | 87 enum GlobalDetachmentBehavior { DoNotDetachGlobal, DetachGlobal }; |
| 99 void disposeContext(GlobalDetachmentBehavior); | 88 virtual void disposeContext(GlobalDetachmentBehavior); |
| 100 | |
| 101 void setSecurityToken(SecurityOrigin*); | |
| 102 | |
| 103 // The JavaScript wrapper for the document object is cached on the global | |
| 104 // object for fast access. UpdateDocumentProperty sets the wrapper | |
| 105 // for the current document on the global object. | |
| 106 void updateDocumentProperty(); | |
| 107 | |
| 108 // Updates Activity Logger for the current context. | |
| 109 void updateActivityLogger(); | |
| 110 | |
| 111 // Creates a new v8::Context with the window wrapper object as the global | |
| 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 | 89 |
| 117 // Associates the window wrapper and its prototype chain with the native | 90 // Associates the window wrapper and its prototype chain with the native |
| 118 // DOMWindow object. Also does some more Window-specific initialization. | 91 // DOMWindow object. Also does some more Window-specific initialization. |
| 119 void setupWindowPrototypeChain(); | 92 void setupWindowPrototypeChain(); |
| 120 | 93 |
| 121 Member<Frame> m_frame; | 94 Frame* frame() const { return m_frame.get(); } |
| 122 v8::Isolate* m_isolate; | 95 v8::Isolate* isolate() const { return m_isolate; } |
| 96 ScriptState* getScriptState() const { return m_scriptState.get(); } | |
| 97 | |
| 98 private: | |
| 99 const Member<Frame> m_frame; | |
| 100 v8::Isolate* const m_isolate; | |
| 101 | |
| 102 protected: | |
|
Yuki
2017/01/11 10:09:24
Could you unify two protected: sections into one?
dcheng
2017/01/11 10:35:29
This is a bit messy right now. However, the reason
| |
| 103 // TODO(dcheng): Move this to LocalWindowProxy once RemoteWindowProxy uses | |
| 104 // remote contexts. | |
| 123 RefPtr<ScriptState> m_scriptState; | 105 RefPtr<ScriptState> m_scriptState; |
| 124 RefPtr<DOMWrapperWorld> m_world; | 106 // TODO(dcheng): Consider making these private and using getters. |
| 107 const RefPtr<DOMWrapperWorld> m_world; | |
| 125 ScopedPersistent<v8::Object> m_globalProxy; | 108 ScopedPersistent<v8::Object> m_globalProxy; |
| 126 Lifecycle m_lifecycle; | 109 Lifecycle m_lifecycle; |
| 127 }; | 110 }; |
| 128 | 111 |
| 129 } // namespace blink | 112 } // namespace blink |
| 130 | 113 |
| 131 #endif // WindowProxy_h | 114 #endif // WindowProxy_h |
| OLD | NEW |