Chromium Code Reviews| 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 // 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.
| |
| 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 UnknownWorldId = -1, | |
| 57 MainWorldId = 0, | |
| 58 // Embedder isolated worlds can use IDs in [1, 1<<29). | |
| 59 EmbedderWorldIdLimit = (1 << 29), | |
| 60 DocumentXMLTreeViewerWorldId, | |
| 61 IsolatedWorldIdLimit, | |
| 62 WorkerWorldId, | |
| 63 }; | |
| 64 | 64 |
| 65 enum class WorldType { | |
| 66 Unknown, | |
| 67 Main, | |
| 68 Isolated, | |
| 69 Worker, | |
| 70 }; | |
| 71 | |
| 72 // Creates a world other than IsolatedWorld. | |
| 73 static PassRefPtr<DOMWrapperWorld> create(v8::Isolate*, WorldType); | |
| 74 | |
| 75 // Ensures an IsolatedWorld for |worldId|. | |
| 65 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(v8::Isolate*, | 76 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(v8::Isolate*, |
| 66 int worldId); | 77 int worldId); |
| 67 ~DOMWrapperWorld(); | 78 ~DOMWrapperWorld(); |
| 68 void dispose(); | 79 void dispose(); |
| 69 | 80 |
| 70 static bool isolatedWorldsExist() { return isolatedWorldCount; } | 81 static bool isolatedWorldsExist() { return isolatedWorldCount; } |
| 71 static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld>>& worlds); | 82 static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld>>& worlds); |
| 72 static void markWrappersInAllWorlds(ScriptWrappable*, | 83 static void markWrappersInAllWorlds(ScriptWrappable*, |
| 73 const ScriptWrappableVisitor*); | 84 const ScriptWrappableVisitor*); |
| 74 | 85 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 99 // world should be restricted based on the isolated world's DOM, not the | 110 // world should be restricted based on the isolated world's DOM, not the |
| 100 // main world's. | 111 // main world's. |
| 101 // | 112 // |
| 102 // FIXME: Right now, resource injection simply bypasses the main world's | 113 // FIXME: Right now, resource injection simply bypasses the main world's |
| 103 // DOM. More work is necessary to allow the isolated world's policy to be | 114 // DOM. More work is necessary to allow the isolated world's policy to be |
| 104 // applied correctly. | 115 // applied correctly. |
| 105 static void setIsolatedWorldContentSecurityPolicy(int worldId, | 116 static void setIsolatedWorldContentSecurityPolicy(int worldId, |
| 106 const String& policy); | 117 const String& policy); |
| 107 bool isolatedWorldHasContentSecurityPolicy(); | 118 bool isolatedWorldHasContentSecurityPolicy(); |
| 108 | 119 |
| 109 bool isMainWorld() const { return m_worldId == MainWorldId; } | 120 bool isMainWorld() const { return m_worldType == WorldType::Main; } |
| 110 bool isWorkerWorld() const { return m_worldId == WorkerWorldId; } | 121 bool isWorkerWorld() const { return m_worldType == WorldType::Worker; } |
| 111 bool isIsolatedWorld() const { | 122 bool isIsolatedWorld() const { return m_worldType == WorldType::Isolated; } |
| 112 return MainWorldId < m_worldId && m_worldId < IsolatedWorldIdLimit; | |
| 113 } | |
| 114 | 123 |
| 115 int worldId() const { return m_worldId; } | 124 int worldId() const { return m_worldId; } |
| 116 DOMDataStore& domDataStore() const { return *m_domDataStore; } | 125 DOMDataStore& domDataStore() const { return *m_domDataStore; } |
| 117 | 126 |
| 118 public: | 127 public: |
| 119 template <typename T> | 128 template <typename T> |
| 120 void registerDOMObjectHolder(v8::Isolate*, T*, v8::Local<v8::Value>); | 129 void registerDOMObjectHolder(v8::Isolate*, T*, v8::Local<v8::Value>); |
| 121 | 130 |
| 122 private: | 131 private: |
| 123 DOMWrapperWorld(v8::Isolate*, int worldId); | 132 DOMWrapperWorld(v8::Isolate*, WorldType, int worldId); |
| 124 | 133 |
| 125 static void weakCallbackForDOMObjectHolder( | 134 static void weakCallbackForDOMObjectHolder( |
| 126 const v8::WeakCallbackInfo<DOMObjectHolderBase>&); | 135 const v8::WeakCallbackInfo<DOMObjectHolderBase>&); |
| 127 void registerDOMObjectHolderInternal(std::unique_ptr<DOMObjectHolderBase>); | 136 void registerDOMObjectHolderInternal(std::unique_ptr<DOMObjectHolderBase>); |
| 128 void unregisterDOMObjectHolder(DOMObjectHolderBase*); | 137 void unregisterDOMObjectHolder(DOMObjectHolderBase*); |
| 129 | 138 |
| 139 // Returns an identifier for a given world type other than | |
| 140 // WorldType::Isolated. IsolatedWorld has its unique convention to allocate an | |
| 141 // identifier. | |
| 142 static int getWorldIdForType(WorldType); | |
| 143 | |
| 130 static unsigned isolatedWorldCount; | 144 static unsigned isolatedWorldCount; |
| 131 | 145 |
| 146 const WorldType m_worldType; | |
| 132 const int m_worldId; | 147 const int m_worldId; |
| 133 std::unique_ptr<DOMDataStore> m_domDataStore; | 148 std::unique_ptr<DOMDataStore> m_domDataStore; |
| 134 HashSet<std::unique_ptr<DOMObjectHolderBase>> m_domObjectHolders; | 149 HashSet<std::unique_ptr<DOMObjectHolderBase>> m_domObjectHolders; |
| 135 }; | 150 }; |
| 136 | 151 |
| 137 } // namespace blink | 152 } // namespace blink |
| 138 | 153 |
| 139 #endif // DOMWrapperWorld_h | 154 #endif // DOMWrapperWorld_h |
| OLD | NEW |