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

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

Issue 2848653003: Add a DevTools command to create an isolated world for a given frame (Closed)
Patch Set: Fix test Created 3 years, 7 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 class PLATFORM_EXPORT DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { 52 class PLATFORM_EXPORT DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {
53 public: 53 public:
54 // Per-thread global identifiers for DOMWrapperWorld. 54 // Per-thread global identifiers for DOMWrapperWorld.
55 enum WorldId { 55 enum WorldId {
56 kInvalidWorldId = -1, 56 kInvalidWorldId = -1,
57 kMainWorldId = 0, 57 kMainWorldId = 0,
58 58
59 // Embedder isolated worlds can use IDs in [1, 1<<29). 59 // Embedder isolated worlds can use IDs in [1, 1<<29).
60 kEmbedderWorldIdLimit = (1 << 29), 60 kEmbedderWorldIdLimit = (1 << 29),
61 kDocumentXMLTreeViewerWorldId, 61 kDocumentXMLTreeViewerWorldId,
62 kDevToolsFirstIsolatedWorldId,
63 kDevToolsLastIsolatedWorldId = kDevToolsFirstIsolatedWorldId + 100,
62 kIsolatedWorldIdLimit, 64 kIsolatedWorldIdLimit,
63 65
64 // Other worlds can use IDs after this. Don't manually pick up an ID from 66 // Other worlds can use IDs after this. Don't manually pick up an ID from
65 // this range. generateWorldIdForType() picks it up on behalf of you. 67 // this range. generateWorldIdForType() picks it up on behalf of you.
66 kUnspecifiedWorldIdStart, 68 kUnspecifiedWorldIdStart,
67 }; 69 };
68 70
69 enum class WorldType { 71 enum class WorldType {
70 kMain, 72 kMain,
71 kIsolated, 73 kIsolated,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 DOMDataStore& DomDataStore() const { return *dom_data_store_; } 136 DOMDataStore& DomDataStore() const { return *dom_data_store_; }
135 137
136 template <typename T> 138 template <typename T>
137 void RegisterDOMObjectHolder(v8::Isolate* isolate, 139 void RegisterDOMObjectHolder(v8::Isolate* isolate,
138 T* object, 140 T* object,
139 v8::Local<v8::Value> wrapper) { 141 v8::Local<v8::Value> wrapper) {
140 RegisterDOMObjectHolderInternal( 142 RegisterDOMObjectHolderInternal(
141 DOMObjectHolder<T>::Create(isolate, object, wrapper)); 143 DOMObjectHolder<T>::Create(isolate, object, wrapper));
142 } 144 }
143 145
146 // Returns an identifier for a given world type. This must not be called for
147 // WorldType::IsolatedWorld because an identifier for the world is given from
148 // out of DOMWrapperWorld.
149 static int GenerateWorldIdForType(WorldType);
150
144 private: 151 private:
145 class DOMObjectHolderBase { 152 class DOMObjectHolderBase {
146 USING_FAST_MALLOC(DOMObjectHolderBase); 153 USING_FAST_MALLOC(DOMObjectHolderBase);
147 154
148 public: 155 public:
149 DOMObjectHolderBase(v8::Isolate* isolate, v8::Local<v8::Value> wrapper) 156 DOMObjectHolderBase(v8::Isolate* isolate, v8::Local<v8::Value> wrapper)
150 : wrapper_(isolate, wrapper), world_(nullptr) {} 157 : wrapper_(isolate, wrapper), world_(nullptr) {}
151 virtual ~DOMObjectHolderBase() {} 158 virtual ~DOMObjectHolderBase() {}
152 159
153 DOMWrapperWorld* World() const { return world_; } 160 DOMWrapperWorld* World() const { return world_; }
(...skipping 26 matching lines...) Expand all
180 187
181 DOMWrapperWorld(v8::Isolate*, WorldType, int world_id); 188 DOMWrapperWorld(v8::Isolate*, WorldType, int world_id);
182 189
183 static void WeakCallbackForDOMObjectHolder( 190 static void WeakCallbackForDOMObjectHolder(
184 const v8::WeakCallbackInfo<DOMObjectHolderBase>&); 191 const v8::WeakCallbackInfo<DOMObjectHolderBase>&);
185 void RegisterDOMObjectHolderInternal(std::unique_ptr<DOMObjectHolderBase>); 192 void RegisterDOMObjectHolderInternal(std::unique_ptr<DOMObjectHolderBase>);
186 void UnregisterDOMObjectHolder(DOMObjectHolderBase*); 193 void UnregisterDOMObjectHolder(DOMObjectHolderBase*);
187 194
188 static unsigned number_of_non_main_worlds_in_main_thread_; 195 static unsigned number_of_non_main_worlds_in_main_thread_;
189 196
190 // Returns an identifier for a given world type. This must not be called for 197 // Returns an id in the range
191 // WorldType::IsolatedWorld because an identifier for the world is given from 198 // [kDevToolsFirstIsolatedWorldId, kDevToolsLastIsolatedWorldId] or
192 // out of DOMWrapperWorld. 199 // kInvalidWorldId if that range has been exhausted.
193 static int GenerateWorldIdForType(WorldType); 200 static int GetNextDevToolsIsolatedWorldId();
pfeldman 2017/05/08 20:27:12 I would go all the way and introduce WorldType for
alex clarke (OOO till 29th) 2017/05/09 08:19:06 Done. I've also renamed all the DevTools reference
194 201
195 // Dissociates all wrappers in all worlds associated with |script_wrappable|. 202 // Dissociates all wrappers in all worlds associated with |script_wrappable|.
196 // 203 //
197 // Do not use this function except for DOMWindow. Only DOMWindow needs to 204 // Do not use this function except for DOMWindow. Only DOMWindow needs to
198 // dissociate wrappers from the ScriptWrappable because of the following two 205 // dissociate wrappers from the ScriptWrappable because of the following two
199 // reasons. 206 // reasons.
200 // 207 //
201 // Reason 1) Case of the main world 208 // Reason 1) Case of the main world
202 // A DOMWindow may be collected by Blink GC *before* V8 GC collects the 209 // A DOMWindow may be collected by Blink GC *before* V8 GC collects the
203 // wrapper because the wrapper object associated with a DOMWindow is a global 210 // wrapper because the wrapper object associated with a DOMWindow is a global
(...skipping 14 matching lines...) Expand all
218 225
219 const WorldType world_type_; 226 const WorldType world_type_;
220 const int world_id_; 227 const int world_id_;
221 std::unique_ptr<DOMDataStore> dom_data_store_; 228 std::unique_ptr<DOMDataStore> dom_data_store_;
222 HashSet<std::unique_ptr<DOMObjectHolderBase>> dom_object_holders_; 229 HashSet<std::unique_ptr<DOMObjectHolderBase>> dom_object_holders_;
223 }; 230 };
224 231
225 } // namespace blink 232 } // namespace blink
226 233
227 #endif // DOMWrapperWorld_h 234 #endif // DOMWrapperWorld_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698