Index: third_party/WebKit/Source/bindings/core/v8/ScriptController.cpp |
diff --git a/third_party/WebKit/Source/bindings/core/v8/ScriptController.cpp b/third_party/WebKit/Source/bindings/core/v8/ScriptController.cpp |
index 8f03da4fe08d79e3a69f87743a86a5ce465c4aad..a3b05cb65202906b239b01a79cc2075f763fbd3b 100644 |
--- a/third_party/WebKit/Source/bindings/core/v8/ScriptController.cpp |
+++ b/third_party/WebKit/Source/bindings/core/v8/ScriptController.cpp |
@@ -60,6 +60,7 @@ |
#include "platform/instrumentation/tracing/TraceEvent.h" |
#include "platform/weborigin/SecurityOrigin.h" |
#include "platform/wtf/CurrentTime.h" |
+#include "platform/wtf/HashSet.h" |
#include "platform/wtf/StdLibExtras.h" |
#include "platform/wtf/StringExtras.h" |
#include "platform/wtf/text/CString.h" |
@@ -371,4 +372,29 @@ void ScriptController::ExecuteScriptInIsolatedWorld( |
} |
} |
+int ScriptController::CreateNewIsolatedWorld(const String& world_name) { |
+ // Find an unused id, unfortunately there doesn't seem to be a better way of |
+ // doing this because DOMWrapperWorld::Create doesn't support isolated worlds. |
+ Vector<RefPtr<DOMWrapperWorld>> worlds; |
+ DOMWrapperWorld::AllWorldsInCurrentThread(worlds); |
+ WTF::HashSet<int> existingWorlds; |
+ for (const auto& world : worlds) { |
+ if (!world->IsIsolatedWorld()) |
+ continue; |
+ existingWorlds.insert(world->GetWorldId()); |
+ } |
+ int world_id = 1; |
caseq
2017/04/28 21:41:30
I think allocating ids like this is going to bring
Sami
2017/05/02 09:47:19
Is there some registry of world ids? Should we jus
alex clarke (OOO till 29th)
2017/05/02 10:00:06
OK do you have any suggestions for what else we mi
|
+ while (existingWorlds.Contains(world_id)) { |
+ world_id++; |
+ } |
+ DCHECK_LT(world_id, DOMWrapperWorld::kEmbedderWorldIdLimit); |
+ RefPtr<DOMWrapperWorld> world = |
+ DOMWrapperWorld::EnsureIsolatedWorld(GetIsolate(), world_id); |
+ |
+ DOMWrapperWorld::SetIsolatedWorldHumanReadableName(world_id, world_name); |
+ // Make sure the execution context exists. |
+ WindowProxy(*world); |
+ return world_id; |
+} |
+ |
} // namespace blink |