Chromium Code Reviews| 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 4970d3eb581defda0a55c13184f2e83fd9c5ecb4..5624c6faa3b29fced3700793973a8c9107e60f40 100644 |
| --- a/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.h |
| +++ b/third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.h |
| @@ -44,24 +44,35 @@ |
| 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 |
| +// WorldIdSpace above). |
|
Yuki
2017/03/08 14:07:51
nit: Could you update the comment?
Not WorldIdSpac
nhiroki
2017/03/09 03:40:29
Done.
|
| 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 { |
| + UnknownWorldId = -1, |
| + MainWorldId = 0, |
| + // Embedder isolated worlds can use IDs in [1, 1<<29). |
| + EmbedderWorldIdLimit = (1 << 29), |
| + DocumentXMLTreeViewerWorldId, |
| + IsolatedWorldIdLimit, |
| + WorkerWorldId, |
| + }; |
| + |
| + enum class WorldType { |
| + Unknown, |
| + Main, |
| + Isolated, |
| + 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(); |
| @@ -106,11 +117,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; } |
| @@ -120,15 +129,21 @@ 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>&); |
| void registerDOMObjectHolderInternal(std::unique_ptr<DOMObjectHolderBase>); |
| void unregisterDOMObjectHolder(DOMObjectHolderBase*); |
| + // Returns an identifier for a given world type other than |
| + // WorldType::Isolated. IsolatedWorld has its unique convention to allocate an |
| + // identifier. |
| + static int getWorldIdForType(WorldType); |
| + |
| static unsigned isolatedWorldCount; |
| + const WorldType m_worldType; |
| const int m_worldId; |
| std::unique_ptr<DOMDataStore> m_domDataStore; |
| HashSet<std::unique_ptr<DOMObjectHolderBase>> m_domObjectHolders; |