Index: third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.h |
diff --git a/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.h b/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.h |
index fa016a0520c313ce81bc4c0c4edefa97f843ffcd..fefb76de14bc9e01517963b239412b481cb2cb22 100644 |
--- a/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.h |
+++ b/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.h |
@@ -44,24 +44,44 @@ |
namespace blink { |
class DOMDataStore; |
- |
-enum WorldIdConstants { |
- MainWorldId = 0, |
- // Embedder isolated worlds can use IDs in [1, 1<<29). |
- EmbedderWorldIdLimit = (1 << 29), |
- DocumentXMLTreeViewerWorldId, |
- IsolatedWorldIdLimit, |
- WorkerWorldId, |
- TestingWorldId, |
-}; |
- |
class DOMObjectHolderBase; |
-// This class represent a collection of DOM wrappers for a specific world. |
+// This class represent a collection of DOM wrappers for a specific world. This |
+// is identified by a world id that is a per-thread global identifier (see |
+// WorldId enum). |
class CORE_EXPORT DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { |
public: |
- static PassRefPtr<DOMWrapperWorld> create(v8::Isolate*, int worldId = -1); |
- |
+ // Per-thread global identifiers for DOMWrapperWorld. |
+ enum WorldId { |
+ InvalidWorldId = -1, |
+ MainWorldId = 0, |
+ |
+ // Embedder isolated worlds can use IDs in [1, 1<<29). |
+ EmbedderWorldIdLimit = (1 << 29), |
+ DocumentXMLTreeViewerWorldId, |
+ IsolatedWorldIdLimit, |
+ |
+ // TODO(nhiroki): Dynamically allocate a world id for the following worlds |
+ // instead of a fixed value (https://crbug.com/697622). |
+ GarbageCollectorWorldId, |
+ RegExpWorldId, |
+ TestingWorldId, |
+ WorkerWorldId, |
+ }; |
+ |
+ enum class WorldType { |
+ Main, |
+ Isolated, |
+ GarbageCollector, |
+ RegExp, |
+ Testing, |
+ Worker, |
+ }; |
+ |
+ // Creates a world other than IsolatedWorld. |
+ static PassRefPtr<DOMWrapperWorld> create(v8::Isolate*, WorldType); |
+ |
+ // Ensures an IsolatedWorld for |worldId|. |
static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(v8::Isolate*, |
int worldId); |
~DOMWrapperWorld(); |
@@ -108,11 +128,9 @@ class CORE_EXPORT DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { |
const String& policy); |
bool isolatedWorldHasContentSecurityPolicy(); |
- bool isMainWorld() const { return m_worldId == MainWorldId; } |
- bool isWorkerWorld() const { return m_worldId == WorkerWorldId; } |
- bool isIsolatedWorld() const { |
- return MainWorldId < m_worldId && m_worldId < IsolatedWorldIdLimit; |
- } |
+ bool isMainWorld() const { return m_worldType == WorldType::Main; } |
+ bool isWorkerWorld() const { return m_worldType == WorldType::Worker; } |
+ bool isIsolatedWorld() const { return m_worldType == WorldType::Isolated; } |
int worldId() const { return m_worldId; } |
DOMDataStore& domDataStore() const { return *m_domDataStore; } |
@@ -122,7 +140,7 @@ class CORE_EXPORT DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { |
void registerDOMObjectHolder(v8::Isolate*, T*, v8::Local<v8::Value>); |
private: |
- DOMWrapperWorld(v8::Isolate*, int worldId); |
+ DOMWrapperWorld(v8::Isolate*, WorldType, int worldId); |
static void weakCallbackForDOMObjectHolder( |
const v8::WeakCallbackInfo<DOMObjectHolderBase>&); |
@@ -131,6 +149,12 @@ class CORE_EXPORT DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { |
static unsigned s_numberOfNonMainWorldsInMainThread; |
+ // Returns an identifier for a given world type. This must not call for |
+ // WorldType::IsolatedWorld because an identifier for the world is given from |
+ // out of DOMWrapperWorld. |
+ static int getWorldIdForType(WorldType); |
+ |
+ const WorldType m_worldType; |
const int m_worldId; |
std::unique_ptr<DOMDataStore> m_domDataStore; |
HashSet<std::unique_ptr<DOMObjectHolderBase>> m_domObjectHolders; |