diff options
Diffstat (limited to 'chromium/third_party/WebKit/Source/bindings/v8/DOMWrapperWorld.h')
-rw-r--r-- | chromium/third_party/WebKit/Source/bindings/v8/DOMWrapperWorld.h | 83 |
1 files changed, 41 insertions, 42 deletions
diff --git a/chromium/third_party/WebKit/Source/bindings/v8/DOMWrapperWorld.h b/chromium/third_party/WebKit/Source/bindings/v8/DOMWrapperWorld.h index 201e019309f..aa294a1fcfb 100644 --- a/chromium/third_party/WebKit/Source/bindings/v8/DOMWrapperWorld.h +++ b/chromium/third_party/WebKit/Source/bindings/v8/DOMWrapperWorld.h @@ -31,54 +31,67 @@ #ifndef DOMWrapperWorld_h #define DOMWrapperWorld_h -#include "bindings/v8/V8DOMActivityLogger.h" -#include "bindings/v8/V8PerContextData.h" +#include "bindings/v8/ScriptState.h" #include "platform/weborigin/SecurityOrigin.h" -#include <v8.h> +#include "wtf/MainThread.h" #include "wtf/PassRefPtr.h" #include "wtf/RefCounted.h" #include "wtf/RefPtr.h" #include "wtf/text/WTFString.h" +#include <v8.h> namespace WebCore { class DOMDataStore; -class ScriptController; class ExecutionContext; +class ScriptController; enum WorldIdConstants { MainWorldId = 0, + // Embedder isolated worlds can use IDs in [1, 1<<29). EmbedderWorldIdLimit = (1 << 29), - ScriptPreprocessorIsolatedWorldId + ScriptPreprocessorIsolatedWorldId, + IsolatedWorldIdLimit, + WorkerWorldId, + TestingWorldId, }; // This class represent a collection of DOM wrappers for a specific world. class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { public: + static PassRefPtr<DOMWrapperWorld> create(int worldId = -1, int extensionGroup = -1); + static const int mainWorldExtensionGroup = 0; static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(int worldId, int extensionGroup); ~DOMWrapperWorld(); + void dispose(); static bool isolatedWorldsExist() { return isolatedWorldCount; } - static bool isIsolatedWorldId(int worldId) { return worldId > MainWorldId; } - static void getAllWorlds(Vector<RefPtr<DOMWrapperWorld> >& worlds); + static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld> >& worlds); - void setIsolatedWorldField(v8::Handle<v8::Context>); + static DOMWrapperWorld& world(v8::Handle<v8::Context> context) + { + return ScriptState::from(context)->world(); + } - static DOMWrapperWorld* isolatedWorld(v8::Handle<v8::Context> context) + static DOMWrapperWorld& current(v8::Isolate* isolate) { - ASSERT(contextHasCorrectPrototype(context)); - return V8PerContextDataHolder::from(context)->isolatedWorld(); + if (isMainThread() && worldOfInitializingWindow) { + // It's possible that current() is being called while window is being initialized. + // In order to make current() workable during the initialization phase, + // we cache the world of the initializing window on worldOfInitializingWindow. + // If there is no initiazing window, worldOfInitializingWindow is 0. + return *worldOfInitializingWindow; + } + return world(isolate->GetCurrentContext()); } - // Will return null if there is no DOMWrapperWorld for the current v8::Context - static DOMWrapperWorld* current(); + static DOMWrapperWorld& mainWorld(); // Associates an isolated world (see above for description) with a security // origin. XMLHttpRequest instances used in that world will be considered // to come from that origin, not the frame's. - static void setIsolatedWorldSecurityOrigin(int worldID, PassRefPtr<SecurityOrigin>); - static void clearIsolatedWorldSecurityOrigin(int worldID); + static void setIsolatedWorldSecurityOrigin(int worldId, PassRefPtr<SecurityOrigin>); SecurityOrigin* isolatedWorldSecurityOrigin(); // Associated an isolated world with a Content Security Policy. Resources @@ -89,50 +102,36 @@ public: // FIXME: Right now, resource injection simply bypasses the main world's // DOM. More work is necessary to allow the isolated world's policy to be // applied correctly. - static void setIsolatedWorldContentSecurityPolicy(int worldID, const String& policy); - static void clearIsolatedWorldContentSecurityPolicy(int worldID); + static void setIsolatedWorldContentSecurityPolicy(int worldId, const String& policy); bool isolatedWorldHasContentSecurityPolicy(); - // Associate a logger with the world identified by worldId (worlId may be 0 - // identifying the main world). - static void setActivityLogger(int worldId, PassOwnPtr<V8DOMActivityLogger>); - static V8DOMActivityLogger* activityLogger(int worldId); - bool isMainWorld() const { return m_worldId == MainWorldId; } - bool isIsolatedWorld() const { return isIsolatedWorldId(m_worldId); } + bool isWorkerWorld() const { return m_worldId == WorkerWorldId; } + bool isIsolatedWorld() const { return MainWorldId < m_worldId && m_worldId < IsolatedWorldIdLimit; } int worldId() const { return m_worldId; } int extensionGroup() const { return m_extensionGroup; } - DOMDataStore& isolatedWorldDOMDataStore() const + DOMDataStore& domDataStore() const { return *m_domDataStore; } + + static void setWorldOfInitializingWindow(DOMWrapperWorld* world) { - ASSERT(isIsolatedWorld()); - return *m_domDataStore; + ASSERT(isMainThread()); + worldOfInitializingWindow = world; } - v8::Handle<v8::Context> context(ScriptController&); - - static void setInitializingWindow(bool); + // FIXME: Remove this method once we fix crbug.com/345014. + static bool windowIsBeingInitialized() { return !!worldOfInitializingWindow; } private: - static unsigned isolatedWorldCount; - static PassRefPtr<DOMWrapperWorld> createMainWorld(); - static bool contextHasCorrectPrototype(v8::Handle<v8::Context>); - DOMWrapperWorld(int worldId, int extensionGroup); + static unsigned isolatedWorldCount; + static DOMWrapperWorld* worldOfInitializingWindow; + const int m_worldId; const int m_extensionGroup; OwnPtr<DOMDataStore> m_domDataStore; - - friend DOMWrapperWorld* mainThreadNormalWorld(); - friend DOMWrapperWorld* existingWindowShellWorkaroundWorld(); }; -DOMWrapperWorld* mainThreadNormalWorld(); - -// FIXME: this is a workaround for a problem in ScriptController -// Do not use this anywhere else!! -DOMWrapperWorld* existingWindowShellWorkaroundWorld(); - } // namespace WebCore #endif // DOMWrapperWorld_h |