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

Side by Side Diff: sky/engine/bindings/core/v8/DOMWrapperWorld.h

Issue 776143003: Remove Isolated Worlds from Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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 28 matching lines...) Expand all
39 #include "sky/engine/wtf/RefPtr.h" 39 #include "sky/engine/wtf/RefPtr.h"
40 #include "sky/engine/wtf/text/WTFString.h" 40 #include "sky/engine/wtf/text/WTFString.h"
41 #include "v8/include/v8.h" 41 #include "v8/include/v8.h"
42 42
43 namespace blink { 43 namespace blink {
44 44
45 class DOMDataStore; 45 class DOMDataStore;
46 class ExecutionContext; 46 class ExecutionContext;
47 class ScriptController; 47 class ScriptController;
48 48
49 enum WorldIdConstants { 49 enum FakeWorldMarker {
50 MainWorldId = 0, 50 MainWorld,
51 // Embedder isolated worlds can use IDs in [1, 1<<29). 51 FakeWorld, // Used by garbage collection and testing, not sure why.
52 EmbedderWorldIdLimit = (1 << 29),
53 IsolatedWorldIdLimit,
54 TestingWorldId,
55 }; 52 };
56 53
57 // This class represent a collection of DOM wrappers for a specific world. 54 // This class represent a collection of DOM wrappers for a specific world.
58 class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { 55 class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {
59 public: 56 public:
60 static PassRefPtr<DOMWrapperWorld> create(int worldId = -1, int extensionGro up = -1); 57 static PassRefPtr<DOMWrapperWorld> create(FakeWorldMarker);
61 58
62 static const int mainWorldExtensionGroup = 0;
63 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(int worldId, int exte nsionGroup);
64 ~DOMWrapperWorld(); 59 ~DOMWrapperWorld();
65 void dispose(); 60 void dispose();
66 61
67 static bool isolatedWorldsExist() { return isolatedWorldCount; }
68 static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld> >& worlds);
69
70 static DOMWrapperWorld& world(v8::Handle<v8::Context> context) 62 static DOMWrapperWorld& world(v8::Handle<v8::Context> context)
71 { 63 {
72 return ScriptState::from(context)->world(); 64 return ScriptState::from(context)->world();
73 } 65 }
74 66
75 static DOMWrapperWorld& current(v8::Isolate* isolate) 67 static DOMWrapperWorld& current(v8::Isolate* isolate)
76 { 68 {
77 if (isMainThread() && worldOfInitializingWindow) { 69 if (isMainThread() && worldOfInitializingWindow) {
78 // It's possible that current() is being called while window is bein g initialized. 70 // It's possible that current() is being called while window is bein g initialized.
79 // In order to make current() workable during the initialization pha se, 71 // In order to make current() workable during the initialization pha se,
80 // we cache the world of the initializing window on worldOfInitializ ingWindow. 72 // we cache the world of the initializing window on worldOfInitializ ingWindow.
81 // If there is no initiazing window, worldOfInitializingWindow is 0. 73 // If there is no initiazing window, worldOfInitializingWindow is 0.
82 return *worldOfInitializingWindow; 74 return *worldOfInitializingWindow;
83 } 75 }
84 return world(isolate->GetCurrentContext()); 76 return world(isolate->GetCurrentContext());
85 } 77 }
86 78
87 static DOMWrapperWorld& mainWorld(); 79 static DOMWrapperWorld& mainWorld();
88 80
89 static void setIsolatedWorldHumanReadableName(int worldID, const String&); 81 bool isMainWorld() const { return !m_isFakeWorld; }
90 String isolatedWorldHumanReadableName();
91 82
92 bool isMainWorld() const { return m_worldId == MainWorldId; }
93 bool isIsolatedWorld() const { return MainWorldId < m_worldId && m_worldId < IsolatedWorldIdLimit; }
94
95 int worldId() const { return m_worldId; }
96 int extensionGroup() const { return m_extensionGroup; }
97 DOMDataStore& domDataStore() const { return *m_domDataStore; } 83 DOMDataStore& domDataStore() const { return *m_domDataStore; }
98 84
99 static void setWorldOfInitializingWindow(DOMWrapperWorld* world) 85 static void setWorldOfInitializingWindow(DOMWrapperWorld* world)
100 { 86 {
101 ASSERT(isMainThread()); 87 ASSERT(isMainThread());
102 worldOfInitializingWindow = world; 88 worldOfInitializingWindow = world;
103 } 89 }
104 // FIXME: Remove this method once we fix crbug.com/345014. 90 // FIXME: Remove this method once we fix crbug.com/345014.
105 static bool windowIsBeingInitialized() { return !!worldOfInitializingWindow; } 91 static bool windowIsBeingInitialized() { return !!worldOfInitializingWindow; }
106 92
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 }; 131 };
146 132
147 public: 133 public:
148 template<typename T> 134 template<typename T>
149 void registerDOMObjectHolder(v8::Isolate* isolate, T* object, v8::Handle<v8: :Value> wrapper) 135 void registerDOMObjectHolder(v8::Isolate* isolate, T* object, v8::Handle<v8: :Value> wrapper)
150 { 136 {
151 registerDOMObjectHolderInternal(DOMObjectHolder<T>::create(isolate, obje ct, wrapper)); 137 registerDOMObjectHolderInternal(DOMObjectHolder<T>::create(isolate, obje ct, wrapper));
152 } 138 }
153 139
154 private: 140 private:
155 DOMWrapperWorld(int worldId, int extensionGroup); 141 DOMWrapperWorld(FakeWorldMarker);
156 142
157 static void weakCallbackForDOMObjectHolder(const v8::WeakCallbackData<v8::Va lue, DOMObjectHolderBase>&); 143 static void weakCallbackForDOMObjectHolder(const v8::WeakCallbackData<v8::Va lue, DOMObjectHolderBase>&);
158 void registerDOMObjectHolderInternal(PassOwnPtr<DOMObjectHolderBase>); 144 void registerDOMObjectHolderInternal(PassOwnPtr<DOMObjectHolderBase>);
159 void unregisterDOMObjectHolder(DOMObjectHolderBase*); 145 void unregisterDOMObjectHolder(DOMObjectHolderBase*);
160 146
161 static unsigned isolatedWorldCount; 147 static unsigned isolatedWorldCount;
162 static DOMWrapperWorld* worldOfInitializingWindow; 148 static DOMWrapperWorld* worldOfInitializingWindow;
163 149
164 const int m_worldId; 150 bool m_isFakeWorld;
165 const int m_extensionGroup;
166 OwnPtr<DOMDataStore> m_domDataStore; 151 OwnPtr<DOMDataStore> m_domDataStore;
167 HashSet<OwnPtr<DOMObjectHolderBase> > m_domObjectHolders; 152 HashSet<OwnPtr<DOMObjectHolderBase> > m_domObjectHolders;
168 }; 153 };
169 154
170 } // namespace blink 155 } // namespace blink
171 156
172 #endif // SKY_ENGINE_BINDINGS_CORE_V8_DOMWRAPPERWORLD_H_ 157 #endif // SKY_ENGINE_BINDINGS_CORE_V8_DOMWRAPPERWORLD_H_
OLDNEW
« no previous file with comments | « sky/engine/bindings/core/v8/DOMDataStore.h ('k') | sky/engine/bindings/core/v8/DOMWrapperWorld.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698