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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 WorkerWorldId, | 53 WorkerWorldId, |
54 TestingWorldId, | 54 TestingWorldId, |
55 }; | 55 }; |
56 | 56 |
57 class DOMObjectHolderBase; | 57 class DOMObjectHolderBase; |
58 template<typename T> class DOMObjectHolder; | 58 template<typename T> class DOMObjectHolder; |
59 | 59 |
60 // This class represent a collection of DOM wrappers for a specific world. | 60 // This class represent a collection of DOM wrappers for a specific world. |
61 class CORE_EXPORT DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { | 61 class CORE_EXPORT DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { |
62 public: | 62 public: |
63 class OriginWorldPusher { | |
64 WTF_MAKE_NONCOPYABLE(OriginWorldPusher); | |
65 | |
66 public: | |
67 explicit OriginWorldPusher(DOMWrapperWorld& currentWorld, PassRefPtr<DOM WrapperWorld> originWorld) | |
68 : m_oldOriginWorld(currentWorld.m_originWorld) | |
69 , m_currentWorld(currentWorld) | |
70 { | |
71 // "Push" the origin world. | |
72 currentWorld.setOriginWorld(originWorld); | |
73 } | |
74 | |
75 ~OriginWorldPusher() | |
76 { | |
77 // "Pop" the origin world to avoid tainting the entire document. | |
78 m_currentWorld.setOriginWorld(m_oldOriginWorld); | |
79 } | |
80 | |
81 private: | |
82 RefPtr<DOMWrapperWorld> m_oldOriginWorld; | |
83 DOMWrapperWorld& m_currentWorld; | |
haraken
2016/01/21 10:16:15
I'm wondering if we could simplify the logic aroun
Joe Mason
2016/01/21 16:13:50
That seems more complicated to me rather than simp
| |
84 }; | |
85 | |
63 static PassRefPtr<DOMWrapperWorld> create(v8::Isolate*, int worldId = -1, in t extensionGroup = -1); | 86 static PassRefPtr<DOMWrapperWorld> create(v8::Isolate*, int worldId = -1, in t extensionGroup = -1); |
64 | 87 |
65 static const int mainWorldExtensionGroup = 0; | 88 static const int mainWorldExtensionGroup = 0; |
66 static const int privateScriptIsolatedWorldExtensionGroup = 1; | 89 static const int privateScriptIsolatedWorldExtensionGroup = 1; |
67 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(v8::Isolate*, int wor ldId, int extensionGroup); | 90 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(v8::Isolate*, int wor ldId, int extensionGroup); |
68 ~DOMWrapperWorld(); | 91 ~DOMWrapperWorld(); |
69 void dispose(); | 92 void dispose(); |
70 | 93 |
71 static bool isolatedWorldsExist() { return isolatedWorldCount; } | 94 static bool isolatedWorldsExist() { return isolatedWorldCount; } |
72 static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld>>& worlds); | 95 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 | 131 // 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 | 132 // DOM. More work is necessary to allow the isolated world's policy to be |
110 // applied correctly. | 133 // applied correctly. |
111 static void setIsolatedWorldContentSecurityPolicy(int worldId, const String& policy); | 134 static void setIsolatedWorldContentSecurityPolicy(int worldId, const String& policy); |
112 bool isolatedWorldHasContentSecurityPolicy(); | 135 bool isolatedWorldHasContentSecurityPolicy(); |
113 | 136 |
114 bool isMainWorld() const { return m_worldId == MainWorldId; } | 137 bool isMainWorld() const { return m_worldId == MainWorldId; } |
115 bool isPrivateScriptIsolatedWorld() const { return m_worldId == PrivateScrip tIsolatedWorldId; } | 138 bool isPrivateScriptIsolatedWorld() const { return m_worldId == PrivateScrip tIsolatedWorldId; } |
116 bool isWorkerWorld() const { return m_worldId == WorkerWorldId; } | 139 bool isWorkerWorld() const { return m_worldId == WorkerWorldId; } |
117 bool isIsolatedWorld() const { return MainWorldId < m_worldId && m_worldId < IsolatedWorldIdLimit; } | 140 bool isIsolatedWorld() const { return MainWorldId < m_worldId && m_worldId < IsolatedWorldIdLimit; } |
141 void setOriginWorld(PassRefPtr<DOMWrapperWorld> originWorld) | |
142 { | |
143 m_originWorld = originWorld; | |
144 }; | |
145 DOMWrapperWorld* originWorld() | |
146 { | |
147 return isIsolatedWorld() ? this : m_originWorld.get(); | |
148 }; | |
149 bool isOfIsolatedWorldOrigin() const | |
150 { | |
151 return isIsolatedWorld() || (m_originWorld && m_originWorld->isIsolatedW orld()); | |
152 }; | |
118 | 153 |
119 int worldId() const { return m_worldId; } | 154 int worldId() const { return m_worldId; } |
120 int extensionGroup() const { return m_extensionGroup; } | 155 int extensionGroup() const { return m_extensionGroup; } |
156 | |
121 DOMDataStore& domDataStore() const { return *m_domDataStore; } | 157 DOMDataStore& domDataStore() const { return *m_domDataStore; } |
122 | 158 |
123 static void setWorldOfInitializingWindow(DOMWrapperWorld* world) | 159 static void setWorldOfInitializingWindow(DOMWrapperWorld* world) |
124 { | 160 { |
125 ASSERT(isMainThread()); | 161 ASSERT(isMainThread()); |
126 worldOfInitializingWindow = world; | 162 worldOfInitializingWindow = world; |
127 } | 163 } |
128 | 164 |
129 public: | 165 public: |
130 template<typename T> | 166 template<typename T> |
131 void registerDOMObjectHolder(v8::Isolate*, T*, v8::Local<v8::Value>); | 167 void registerDOMObjectHolder(v8::Isolate*, T*, v8::Local<v8::Value>); |
132 | 168 |
133 private: | 169 private: |
134 DOMWrapperWorld(v8::Isolate*, int worldId, int extensionGroup); | 170 DOMWrapperWorld(v8::Isolate*, int worldId, int extensionGroup); |
135 | 171 |
136 static void weakCallbackForDOMObjectHolder(const v8::WeakCallbackInfo<DOMObj ectHolderBase>&); | 172 static void weakCallbackForDOMObjectHolder(const v8::WeakCallbackInfo<DOMObj ectHolderBase>&); |
137 void registerDOMObjectHolderInternal(PassOwnPtr<DOMObjectHolderBase>); | 173 void registerDOMObjectHolderInternal(PassOwnPtr<DOMObjectHolderBase>); |
138 void unregisterDOMObjectHolder(DOMObjectHolderBase*); | 174 void unregisterDOMObjectHolder(DOMObjectHolderBase*); |
139 | 175 |
140 static unsigned isolatedWorldCount; | 176 static unsigned isolatedWorldCount; |
141 static DOMWrapperWorld* worldOfInitializingWindow; | 177 static DOMWrapperWorld* worldOfInitializingWindow; |
142 | 178 |
143 const int m_worldId; | 179 const int m_worldId; |
144 const int m_extensionGroup; | 180 const int m_extensionGroup; |
181 RefPtr<DOMWrapperWorld> m_originWorld; | |
145 OwnPtr<DOMDataStore> m_domDataStore; | 182 OwnPtr<DOMDataStore> m_domDataStore; |
146 HashSet<OwnPtr<DOMObjectHolderBase>> m_domObjectHolders; | 183 HashSet<OwnPtr<DOMObjectHolderBase>> m_domObjectHolders; |
147 }; | 184 }; |
148 | 185 |
149 } // namespace blink | 186 } // namespace blink |
150 | 187 |
151 #endif // DOMWrapperWorld_h | 188 #endif // DOMWrapperWorld_h |
OLD | NEW |