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

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 compile ;) 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,
74 kInspectorIsolated,
72 kGarbageCollector, 75 kGarbageCollector,
73 kRegExp, 76 kRegExp,
74 kTesting, 77 kTesting,
75 kWorker, 78 kWorker,
76 }; 79 };
77 80
78 // Creates a world other than IsolatedWorld. 81 // Creates a world other than IsolatedWorld. Note this can return nullptr if
82 // GenerateWorldIdForType fails to allocate a valid id.
79 static PassRefPtr<DOMWrapperWorld> Create(v8::Isolate*, WorldType); 83 static PassRefPtr<DOMWrapperWorld> Create(v8::Isolate*, WorldType);
80 84
81 // Ensures an IsolatedWorld for |worldId|. 85 // Ensures an IsolatedWorld for |worldId|.
82 static PassRefPtr<DOMWrapperWorld> EnsureIsolatedWorld(v8::Isolate*, 86 static PassRefPtr<DOMWrapperWorld> EnsureIsolatedWorld(v8::Isolate*,
83 int world_id); 87 int world_id);
84 ~DOMWrapperWorld(); 88 ~DOMWrapperWorld();
85 void Dispose(); 89 void Dispose();
86 90
87 // Called from performance-sensitive functions, so we should keep this simple 91 // Called from performance-sensitive functions, so we should keep this simple
88 // and fast as much as possible. 92 // and fast as much as possible.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // 125 //
122 // FIXME: Right now, resource injection simply bypasses the main world's 126 // FIXME: Right now, resource injection simply bypasses the main world's
123 // DOM. More work is necessary to allow the isolated world's policy to be 127 // DOM. More work is necessary to allow the isolated world's policy to be
124 // applied correctly. 128 // applied correctly.
125 static void SetIsolatedWorldContentSecurityPolicy(int world_id, 129 static void SetIsolatedWorldContentSecurityPolicy(int world_id,
126 const String& policy); 130 const String& policy);
127 bool IsolatedWorldHasContentSecurityPolicy(); 131 bool IsolatedWorldHasContentSecurityPolicy();
128 132
129 bool IsMainWorld() const { return world_type_ == WorldType::kMain; } 133 bool IsMainWorld() const { return world_type_ == WorldType::kMain; }
130 bool IsWorkerWorld() const { return world_type_ == WorldType::kWorker; } 134 bool IsWorkerWorld() const { return world_type_ == WorldType::kWorker; }
131 bool IsIsolatedWorld() const { return world_type_ == WorldType::kIsolated; } 135 bool IsIsolatedWorld() const {
136 return world_type_ == WorldType::kIsolated ||
137 world_type_ == WorldType::kInspectorIsolated;
138 }
132 139
133 int GetWorldId() const { return world_id_; } 140 int GetWorldId() const { return world_id_; }
134 DOMDataStore& DomDataStore() const { return *dom_data_store_; } 141 DOMDataStore& DomDataStore() const { return *dom_data_store_; }
135 142
136 template <typename T> 143 template <typename T>
137 void RegisterDOMObjectHolder(v8::Isolate* isolate, 144 void RegisterDOMObjectHolder(v8::Isolate* isolate,
138 T* object, 145 T* object,
139 v8::Local<v8::Value> wrapper) { 146 v8::Local<v8::Value> wrapper) {
140 RegisterDOMObjectHolderInternal( 147 RegisterDOMObjectHolderInternal(
141 DOMObjectHolder<T>::Create(isolate, object, wrapper)); 148 DOMObjectHolder<T>::Create(isolate, object, wrapper));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 identifier for a given world type. This must not be called for
191 // WorldType::IsolatedWorld because an identifier for the world is given from 198 // WorldType::IsolatedWorld because an identifier for the world is given from
192 // out of DOMWrapperWorld. 199 // out of DOMWrapperWorld.
193 static int GenerateWorldIdForType(WorldType); 200 static int GenerateWorldIdForType(WorldType);
194 201
202 // Returns an id in the range
203 // [kDevToolsFirstIsolatedWorldId, kDevToolsLastIsolatedWorldId] or
204 // kInvalidWorldId if that range has been exhausted.
205 static int GetNextInspectorIsolatedWorldId();
pfeldman 2017/05/09 18:57:36 do you still need it?
alex clarke (OOO till 29th) 2017/05/09 19:40:36 It's gone.
206
195 // Dissociates all wrappers in all worlds associated with |script_wrappable|. 207 // Dissociates all wrappers in all worlds associated with |script_wrappable|.
196 // 208 //
197 // Do not use this function except for DOMWindow. Only DOMWindow needs to 209 // Do not use this function except for DOMWindow. Only DOMWindow needs to
198 // dissociate wrappers from the ScriptWrappable because of the following two 210 // dissociate wrappers from the ScriptWrappable because of the following two
199 // reasons. 211 // reasons.
200 // 212 //
201 // Reason 1) Case of the main world 213 // Reason 1) Case of the main world
202 // A DOMWindow may be collected by Blink GC *before* V8 GC collects the 214 // 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 215 // wrapper because the wrapper object associated with a DOMWindow is a global
204 // proxy, which remains after navigations. We don't want V8 GC to reset the 216 // proxy, which remains after navigations. We don't want V8 GC to reset the
(...skipping 13 matching lines...) Expand all
218 230
219 const WorldType world_type_; 231 const WorldType world_type_;
220 const int world_id_; 232 const int world_id_;
221 std::unique_ptr<DOMDataStore> dom_data_store_; 233 std::unique_ptr<DOMDataStore> dom_data_store_;
222 HashSet<std::unique_ptr<DOMObjectHolderBase>> dom_object_holders_; 234 HashSet<std::unique_ptr<DOMObjectHolderBase>> dom_object_holders_;
223 }; 235 };
224 236
225 } // namespace blink 237 } // namespace blink
226 238
227 #endif // DOMWrapperWorld_h 239 #endif // DOMWrapperWorld_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698