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 DOMWrapperWorld_h | 31 #ifndef DOMWrapperWorld_h |
32 #define DOMWrapperWorld_h | 32 #define DOMWrapperWorld_h |
33 | 33 |
34 #include "bindings/core/v8/ScriptState.h" | 34 #include "bindings/core/v8/ScriptState.h" |
35 #include "core/CoreExport.h" | 35 #include "core/CoreExport.h" |
36 #include "platform/weborigin/SecurityOrigin.h" | 36 #include "platform/weborigin/SecurityOrigin.h" |
37 #include "wtf/MainThread.h" | 37 #include "wtf/MainThread.h" |
| 38 #include "wtf/OwnPtr.h" |
38 #include "wtf/PassRefPtr.h" | 39 #include "wtf/PassRefPtr.h" |
39 #include "wtf/RefCounted.h" | 40 #include "wtf/RefCounted.h" |
40 #include "wtf/RefPtr.h" | 41 #include "wtf/RefPtr.h" |
41 #include <v8.h> | 42 #include <v8.h> |
42 | 43 |
43 namespace blink { | 44 namespace blink { |
44 | 45 |
45 class DOMDataStore; | 46 class DOMDataStore; |
46 | 47 |
47 enum WorldIdConstants { | 48 enum WorldIdConstants { |
48 MainWorldId = 0, | 49 MainWorldId = 0, |
49 // Embedder isolated worlds can use IDs in [1, 1<<29). | 50 // Embedder isolated worlds can use IDs in [1, 1<<29). |
50 EmbedderWorldIdLimit = (1 << 29), | 51 EmbedderWorldIdLimit = (1 << 29), |
51 PrivateScriptIsolatedWorldId, | 52 PrivateScriptIsolatedWorldId, |
52 IsolatedWorldIdLimit, | 53 IsolatedWorldIdLimit, |
53 WorkerWorldId, | 54 WorkerWorldId, |
54 TestingWorldId, | 55 TestingWorldId, |
55 }; | 56 }; |
56 | 57 |
57 class DOMObjectHolderBase; | 58 class DOMObjectHolderBase; |
58 template<typename T> class DOMObjectHolder; | 59 template<typename T> class DOMObjectHolder; |
59 | 60 |
60 // This class represent a collection of DOM wrappers for a specific world. | 61 // This class represent a collection of DOM wrappers for a specific world. |
61 class CORE_EXPORT DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { | 62 class CORE_EXPORT DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { |
62 public: | 63 public: |
| 64 class OriginWorldScope { |
| 65 WTF_MAKE_NONCOPYABLE(OriginWorldScope); |
| 66 |
| 67 public: |
| 68 explicit OriginWorldScope(PassRefPtr<DOMWrapperWorld> originWorld) |
| 69 : m_hasPushed(false) |
| 70 { |
| 71 ASSERT(isMainThread()); |
| 72 if (originWorld) { |
| 73 DOMWrapperWorld::originWorldStack().append(originWorld); |
| 74 m_hasPushed = true; |
| 75 } |
| 76 } |
| 77 |
| 78 ~OriginWorldScope() |
| 79 { |
| 80 ASSERT(isMainThread()); |
| 81 // "Pop" the origin world to avoid tainting the entire document. |
| 82 if (m_hasPushed) { |
| 83 DOMWrapperWorld::originWorldStack().removeLast(); |
| 84 } |
| 85 } |
| 86 |
| 87 private: |
| 88 bool m_hasPushed; |
| 89 }; |
| 90 |
63 static PassRefPtr<DOMWrapperWorld> create(v8::Isolate*, int worldId = -1, in
t extensionGroup = -1); | 91 static PassRefPtr<DOMWrapperWorld> create(v8::Isolate*, int worldId = -1, in
t extensionGroup = -1); |
64 | 92 |
65 static const int mainWorldExtensionGroup = 0; | 93 static const int mainWorldExtensionGroup = 0; |
66 static const int privateScriptIsolatedWorldExtensionGroup = 1; | 94 static const int privateScriptIsolatedWorldExtensionGroup = 1; |
67 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(v8::Isolate*, int wor
ldId, int extensionGroup); | 95 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(v8::Isolate*, int wor
ldId, int extensionGroup); |
68 ~DOMWrapperWorld(); | 96 ~DOMWrapperWorld(); |
69 void dispose(); | 97 void dispose(); |
70 | 98 |
71 static bool isolatedWorldsExist() { return isolatedWorldCount; } | 99 static bool isolatedWorldsExist() { return isolatedWorldCount; } |
72 static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld>>& worlds); | 100 static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld>>& worlds); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // FIXME: Right now, resource injection simply bypasses the main world's | 136 // FIXME: Right now, resource injection simply bypasses the main world's |
109 // DOM. More work is necessary to allow the isolated world's policy to be | 137 // DOM. More work is necessary to allow the isolated world's policy to be |
110 // applied correctly. | 138 // applied correctly. |
111 static void setIsolatedWorldContentSecurityPolicy(int worldId, const String&
policy); | 139 static void setIsolatedWorldContentSecurityPolicy(int worldId, const String&
policy); |
112 bool isolatedWorldHasContentSecurityPolicy(); | 140 bool isolatedWorldHasContentSecurityPolicy(); |
113 | 141 |
114 bool isMainWorld() const { return m_worldId == MainWorldId; } | 142 bool isMainWorld() const { return m_worldId == MainWorldId; } |
115 bool isPrivateScriptIsolatedWorld() const { return m_worldId == PrivateScrip
tIsolatedWorldId; } | 143 bool isPrivateScriptIsolatedWorld() const { return m_worldId == PrivateScrip
tIsolatedWorldId; } |
116 bool isWorkerWorld() const { return m_worldId == WorkerWorldId; } | 144 bool isWorkerWorld() const { return m_worldId == WorkerWorldId; } |
117 bool isIsolatedWorld() const { return MainWorldId < m_worldId && m_worldId
< IsolatedWorldIdLimit; } | 145 bool isIsolatedWorld() const { return MainWorldId < m_worldId && m_worldId
< IsolatedWorldIdLimit; } |
| 146 DOMWrapperWorld* originWorld() |
| 147 { |
| 148 if (isIsolatedWorld()) |
| 149 return this; |
| 150 if (isMainThread() && !originWorldStack().isEmpty()) |
| 151 return originWorldStack().last().get(); |
| 152 return nullptr; |
| 153 }; |
| 154 bool isOfIsolatedWorldOrigin() const |
| 155 { |
| 156 ASSERT(isMainThread()); |
| 157 return isIsolatedWorld() ? true : originWorldStack().isEmpty() ? false :
originWorldStack().last().get()->isIsolatedWorld(); |
| 158 }; |
118 | 159 |
119 int worldId() const { return m_worldId; } | 160 int worldId() const { return m_worldId; } |
120 int extensionGroup() const { return m_extensionGroup; } | 161 int extensionGroup() const { return m_extensionGroup; } |
| 162 |
121 DOMDataStore& domDataStore() const { return *m_domDataStore; } | 163 DOMDataStore& domDataStore() const { return *m_domDataStore; } |
122 | 164 |
123 static void setWorldOfInitializingWindow(DOMWrapperWorld* world) | 165 static void setWorldOfInitializingWindow(DOMWrapperWorld* world) |
124 { | 166 { |
125 ASSERT(isMainThread()); | 167 ASSERT(isMainThread()); |
126 worldOfInitializingWindow = world; | 168 worldOfInitializingWindow = world; |
127 } | 169 } |
128 | 170 |
129 public: | 171 public: |
130 template<typename T> | 172 template<typename T> |
131 void registerDOMObjectHolder(v8::Isolate*, T*, v8::Local<v8::Value>); | 173 void registerDOMObjectHolder(v8::Isolate*, T*, v8::Local<v8::Value>); |
132 | 174 |
133 private: | 175 private: |
134 DOMWrapperWorld(v8::Isolate*, int worldId, int extensionGroup); | 176 DOMWrapperWorld(v8::Isolate*, int worldId, int extensionGroup); |
135 | 177 |
| 178 static Vector<RefPtr<DOMWrapperWorld>>& originWorldStack(); |
| 179 |
136 static void weakCallbackForDOMObjectHolder(const v8::WeakCallbackInfo<DOMObj
ectHolderBase>&); | 180 static void weakCallbackForDOMObjectHolder(const v8::WeakCallbackInfo<DOMObj
ectHolderBase>&); |
137 void registerDOMObjectHolderInternal(PassOwnPtr<DOMObjectHolderBase>); | 181 void registerDOMObjectHolderInternal(PassOwnPtr<DOMObjectHolderBase>); |
138 void unregisterDOMObjectHolder(DOMObjectHolderBase*); | 182 void unregisterDOMObjectHolder(DOMObjectHolderBase*); |
139 | 183 |
140 static unsigned isolatedWorldCount; | 184 static unsigned isolatedWorldCount; |
141 static DOMWrapperWorld* worldOfInitializingWindow; | 185 static DOMWrapperWorld* worldOfInitializingWindow; |
142 | 186 |
143 const int m_worldId; | 187 const int m_worldId; |
144 const int m_extensionGroup; | 188 const int m_extensionGroup; |
145 OwnPtr<DOMDataStore> m_domDataStore; | 189 OwnPtr<DOMDataStore> m_domDataStore; |
146 HashSet<OwnPtr<DOMObjectHolderBase>> m_domObjectHolders; | 190 HashSet<OwnPtr<DOMObjectHolderBase>> m_domObjectHolders; |
147 }; | 191 }; |
148 | 192 |
149 } // namespace blink | 193 } // namespace blink |
150 | 194 |
151 #endif // DOMWrapperWorld_h | 195 #endif // DOMWrapperWorld_h |
OLD | NEW |