Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/DOMWrapperWorld.h

Issue 2735973006: Bindings: Separate WorldIdConstants into WorldTypes and WorldId (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 27 matching lines...) Expand all
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 47
48 enum WorldIdConstants { 48 // Per-thread global identifiers for DOMWrapperWorld.
49 enum WorldIdSpace {
peria 2017/03/08 09:48:19 Can you move this enum into DOMWrapperWorld class?
nhiroki 2017/03/08 10:24:53 Done.
50 UnknownWorldId = -1,
49 MainWorldId = 0, 51 MainWorldId = 0,
50 // Embedder isolated worlds can use IDs in [1, 1<<29). 52 // Embedder isolated worlds can use IDs in [1, 1<<29).
51 EmbedderWorldIdLimit = (1 << 29), 53 EmbedderWorldIdLimit = (1 << 29),
52 DocumentXMLTreeViewerWorldId, 54 DocumentXMLTreeViewerWorldId,
53 IsolatedWorldIdLimit, 55 IsolatedWorldIdLimit,
54 WorkerWorldId, 56 WorkerWorldId,
55 TestingWorldId, 57 };
58
59 enum class WorldType {
60 Unknown,
61 Main,
62 Isolated,
63 Worker,
56 }; 64 };
57 65
58 class DOMObjectHolderBase; 66 class DOMObjectHolderBase;
59 67
60 // This class represent a collection of DOM wrappers for a specific world. 68 // This class represent a collection of DOM wrappers for a specific world. This
69 // is identified by a world id that is a per-thread global identifier (see
70 // WorldIdSpace above).
61 class CORE_EXPORT DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { 71 class CORE_EXPORT DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {
62 public: 72 public:
63 static PassRefPtr<DOMWrapperWorld> create(v8::Isolate*, int worldId = -1); 73 // Creates a world other than IsolatedWorld.
74 static PassRefPtr<DOMWrapperWorld> create(v8::Isolate*, WorldType);
64 75
76 // Ensures an IsolatedWorld for |worldId|.
65 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(v8::Isolate*, 77 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(v8::Isolate*,
66 int worldId); 78 int worldId);
67 ~DOMWrapperWorld(); 79 ~DOMWrapperWorld();
68 void dispose(); 80 void dispose();
69 81
70 static bool isolatedWorldsExist() { return isolatedWorldCount; } 82 static bool isolatedWorldsExist() { return isolatedWorldCount; }
71 static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld>>& worlds); 83 static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld>>& worlds);
72 static void markWrappersInAllWorlds(ScriptWrappable*, 84 static void markWrappersInAllWorlds(ScriptWrappable*,
73 const ScriptWrappableVisitor*); 85 const ScriptWrappableVisitor*);
74 86
(...skipping 24 matching lines...) Expand all
99 // world should be restricted based on the isolated world's DOM, not the 111 // world should be restricted based on the isolated world's DOM, not the
100 // main world's. 112 // main world's.
101 // 113 //
102 // FIXME: Right now, resource injection simply bypasses the main world's 114 // 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 115 // DOM. More work is necessary to allow the isolated world's policy to be
104 // applied correctly. 116 // applied correctly.
105 static void setIsolatedWorldContentSecurityPolicy(int worldId, 117 static void setIsolatedWorldContentSecurityPolicy(int worldId,
106 const String& policy); 118 const String& policy);
107 bool isolatedWorldHasContentSecurityPolicy(); 119 bool isolatedWorldHasContentSecurityPolicy();
108 120
109 bool isMainWorld() const { return m_worldId == MainWorldId; } 121 bool isMainWorld() const { return m_worldType == WorldType::Main; }
110 bool isWorkerWorld() const { return m_worldId == WorkerWorldId; } 122 bool isWorkerWorld() const { return m_worldType == WorldType::Worker; }
111 bool isIsolatedWorld() const { 123 bool isIsolatedWorld() const { return m_worldType == WorldType::Isolated; }
112 return MainWorldId < m_worldId && m_worldId < IsolatedWorldIdLimit;
113 }
114 124
115 int worldId() const { return m_worldId; } 125 int worldId() const { return m_worldId; }
116 DOMDataStore& domDataStore() const { return *m_domDataStore; } 126 DOMDataStore& domDataStore() const { return *m_domDataStore; }
117 127
118 public: 128 public:
119 template <typename T> 129 template <typename T>
120 void registerDOMObjectHolder(v8::Isolate*, T*, v8::Local<v8::Value>); 130 void registerDOMObjectHolder(v8::Isolate*, T*, v8::Local<v8::Value>);
121 131
122 private: 132 private:
123 DOMWrapperWorld(v8::Isolate*, int worldId); 133 DOMWrapperWorld(v8::Isolate*, WorldType, int worldId);
124 134
125 static void weakCallbackForDOMObjectHolder( 135 static void weakCallbackForDOMObjectHolder(
126 const v8::WeakCallbackInfo<DOMObjectHolderBase>&); 136 const v8::WeakCallbackInfo<DOMObjectHolderBase>&);
127 void registerDOMObjectHolderInternal(std::unique_ptr<DOMObjectHolderBase>); 137 void registerDOMObjectHolderInternal(std::unique_ptr<DOMObjectHolderBase>);
128 void unregisterDOMObjectHolder(DOMObjectHolderBase*); 138 void unregisterDOMObjectHolder(DOMObjectHolderBase*);
129 139
130 static unsigned isolatedWorldCount; 140 static unsigned isolatedWorldCount;
131 141
142 const WorldType m_worldType;
132 const int m_worldId; 143 const int m_worldId;
133 std::unique_ptr<DOMDataStore> m_domDataStore; 144 std::unique_ptr<DOMDataStore> m_domDataStore;
134 HashSet<std::unique_ptr<DOMObjectHolderBase>> m_domObjectHolders; 145 HashSet<std::unique_ptr<DOMObjectHolderBase>> m_domObjectHolders;
135 }; 146 };
136 147
137 } // namespace blink 148 } // namespace blink
138 149
139 #endif // DOMWrapperWorld_h 150 #endif // DOMWrapperWorld_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698