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 26 matching lines...) Expand all Loading... |
37 #include "core/CoreExport.h" | 37 #include "core/CoreExport.h" |
38 #include "platform/weborigin/SecurityOrigin.h" | 38 #include "platform/weborigin/SecurityOrigin.h" |
39 #include "v8/include/v8.h" | 39 #include "v8/include/v8.h" |
40 #include "wtf/PassRefPtr.h" | 40 #include "wtf/PassRefPtr.h" |
41 #include "wtf/RefCounted.h" | 41 #include "wtf/RefCounted.h" |
42 #include "wtf/RefPtr.h" | 42 #include "wtf/RefPtr.h" |
43 | 43 |
44 namespace blink { | 44 namespace blink { |
45 | 45 |
46 class DOMDataStore; | 46 class DOMDataStore; |
47 | |
48 enum WorldIdConstants { | |
49 MainWorldId = 0, | |
50 // Embedder isolated worlds can use IDs in [1, 1<<29). | |
51 EmbedderWorldIdLimit = (1 << 29), | |
52 DocumentXMLTreeViewerWorldId, | |
53 IsolatedWorldIdLimit, | |
54 WorkerWorldId, | |
55 TestingWorldId, | |
56 }; | |
57 | |
58 class DOMObjectHolderBase; | 47 class DOMObjectHolderBase; |
59 | 48 |
60 // This class represent a collection of DOM wrappers for a specific world. | 49 // This class represent a collection of DOM wrappers for a specific world. This |
| 50 // is identified by a world id that is a per-thread global identifier (see |
| 51 // WorldId enum). |
61 class CORE_EXPORT DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { | 52 class CORE_EXPORT DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { |
62 public: | 53 public: |
63 static PassRefPtr<DOMWrapperWorld> create(v8::Isolate*, int worldId = -1); | 54 // Per-thread global identifiers for DOMWrapperWorld. |
| 55 enum WorldId { |
| 56 InvalidWorldId = -1, |
| 57 MainWorldId = 0, |
64 | 58 |
| 59 // Embedder isolated worlds can use IDs in [1, 1<<29). |
| 60 EmbedderWorldIdLimit = (1 << 29), |
| 61 DocumentXMLTreeViewerWorldId, |
| 62 IsolatedWorldIdLimit, |
| 63 |
| 64 // TODO(nhiroki): Dynamically allocate a world id for the following worlds |
| 65 // instead of a fixed value (https://crbug.com/697622). |
| 66 GarbageCollectorWorldId, |
| 67 RegExpWorldId, |
| 68 TestingWorldId, |
| 69 WorkerWorldId, |
| 70 }; |
| 71 |
| 72 enum class WorldType { |
| 73 Main, |
| 74 Isolated, |
| 75 GarbageCollector, |
| 76 RegExp, |
| 77 Testing, |
| 78 Worker, |
| 79 }; |
| 80 |
| 81 // Creates a world other than IsolatedWorld. |
| 82 static PassRefPtr<DOMWrapperWorld> create(v8::Isolate*, WorldType); |
| 83 |
| 84 // Ensures an IsolatedWorld for |worldId|. |
65 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(v8::Isolate*, | 85 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(v8::Isolate*, |
66 int worldId); | 86 int worldId); |
67 ~DOMWrapperWorld(); | 87 ~DOMWrapperWorld(); |
68 void dispose(); | 88 void dispose(); |
69 | 89 |
70 static bool nonMainWorldsInMainThread() { | 90 static bool nonMainWorldsInMainThread() { |
71 return s_numberOfNonMainWorldsInMainThread; | 91 return s_numberOfNonMainWorldsInMainThread; |
72 } | 92 } |
73 static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld>>& worlds); | 93 static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld>>& worlds); |
74 static void markWrappersInAllWorlds(ScriptWrappable*, | 94 static void markWrappersInAllWorlds(ScriptWrappable*, |
(...skipping 26 matching lines...) Expand all Loading... |
101 // world should be restricted based on the isolated world's DOM, not the | 121 // world should be restricted based on the isolated world's DOM, not the |
102 // main world's. | 122 // main world's. |
103 // | 123 // |
104 // FIXME: Right now, resource injection simply bypasses the main world's | 124 // FIXME: Right now, resource injection simply bypasses the main world's |
105 // DOM. More work is necessary to allow the isolated world's policy to be | 125 // DOM. More work is necessary to allow the isolated world's policy to be |
106 // applied correctly. | 126 // applied correctly. |
107 static void setIsolatedWorldContentSecurityPolicy(int worldId, | 127 static void setIsolatedWorldContentSecurityPolicy(int worldId, |
108 const String& policy); | 128 const String& policy); |
109 bool isolatedWorldHasContentSecurityPolicy(); | 129 bool isolatedWorldHasContentSecurityPolicy(); |
110 | 130 |
111 bool isMainWorld() const { return m_worldId == MainWorldId; } | 131 bool isMainWorld() const { return m_worldType == WorldType::Main; } |
112 bool isWorkerWorld() const { return m_worldId == WorkerWorldId; } | 132 bool isWorkerWorld() const { return m_worldType == WorldType::Worker; } |
113 bool isIsolatedWorld() const { | 133 bool isIsolatedWorld() const { return m_worldType == WorldType::Isolated; } |
114 return MainWorldId < m_worldId && m_worldId < IsolatedWorldIdLimit; | |
115 } | |
116 | 134 |
117 int worldId() const { return m_worldId; } | 135 int worldId() const { return m_worldId; } |
118 DOMDataStore& domDataStore() const { return *m_domDataStore; } | 136 DOMDataStore& domDataStore() const { return *m_domDataStore; } |
119 | 137 |
120 public: | 138 public: |
121 template <typename T> | 139 template <typename T> |
122 void registerDOMObjectHolder(v8::Isolate*, T*, v8::Local<v8::Value>); | 140 void registerDOMObjectHolder(v8::Isolate*, T*, v8::Local<v8::Value>); |
123 | 141 |
124 private: | 142 private: |
125 DOMWrapperWorld(v8::Isolate*, int worldId); | 143 DOMWrapperWorld(v8::Isolate*, WorldType, int worldId); |
126 | 144 |
127 static void weakCallbackForDOMObjectHolder( | 145 static void weakCallbackForDOMObjectHolder( |
128 const v8::WeakCallbackInfo<DOMObjectHolderBase>&); | 146 const v8::WeakCallbackInfo<DOMObjectHolderBase>&); |
129 void registerDOMObjectHolderInternal(std::unique_ptr<DOMObjectHolderBase>); | 147 void registerDOMObjectHolderInternal(std::unique_ptr<DOMObjectHolderBase>); |
130 void unregisterDOMObjectHolder(DOMObjectHolderBase*); | 148 void unregisterDOMObjectHolder(DOMObjectHolderBase*); |
131 | 149 |
132 static unsigned s_numberOfNonMainWorldsInMainThread; | 150 static unsigned s_numberOfNonMainWorldsInMainThread; |
133 | 151 |
| 152 // Returns an identifier for a given world type. This must not call for |
| 153 // WorldType::IsolatedWorld because an identifier for the world is given from |
| 154 // out of DOMWrapperWorld. |
| 155 static int getWorldIdForType(WorldType); |
| 156 |
| 157 const WorldType m_worldType; |
134 const int m_worldId; | 158 const int m_worldId; |
135 std::unique_ptr<DOMDataStore> m_domDataStore; | 159 std::unique_ptr<DOMDataStore> m_domDataStore; |
136 HashSet<std::unique_ptr<DOMObjectHolderBase>> m_domObjectHolders; | 160 HashSet<std::unique_ptr<DOMObjectHolderBase>> m_domObjectHolders; |
137 }; | 161 }; |
138 | 162 |
139 } // namespace blink | 163 } // namespace blink |
140 | 164 |
141 #endif // DOMWrapperWorld_h | 165 #endif // DOMWrapperWorld_h |
OLD | NEW |