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

Unified Diff: Source/bindings/v8/DOMWrapperWorld.h

Issue 182903003: Make DOMWrapperWorld::current() callable from workers (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/bindings/v8/DOMWrapperWorld.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/v8/DOMWrapperWorld.h
diff --git a/Source/bindings/v8/DOMWrapperWorld.h b/Source/bindings/v8/DOMWrapperWorld.h
index c95fd0031775f58c53b2c51deeecf54b1a0376b8..69385c1184dc2c3edb715e71a2c20d0b2fab9f92 100644
--- a/Source/bindings/v8/DOMWrapperWorld.h
+++ b/Source/bindings/v8/DOMWrapperWorld.h
@@ -33,6 +33,7 @@
#include "bindings/v8/V8PerContextData.h"
#include "platform/weborigin/SecurityOrigin.h"
+#include "wtf/MainThread.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/RefPtr.h"
@@ -70,12 +71,28 @@ public:
static DOMWrapperWorld* world(v8::Handle<v8::Context> context)
{
- ASSERT(contextHasCorrectPrototype(context));
return V8PerContextData::world(context);
}
- // Will return null if there is no DOMWrapperWorld for the current v8::Context
- static DOMWrapperWorld* current(v8::Isolate*);
+ // Will return null if there is no DOMWrapperWorld for the current context.
+ static DOMWrapperWorld* current(v8::Isolate* isolate)
+ {
+ v8::Handle<v8::Context> context = isolate->GetCurrentContext();
+ if (context.IsEmpty()) {
+ // If a worker thread calls current() with an empty context, it means that there is no DOMWrapperWorld.
+ if (!isMainThread())
+ return 0;
+
+ // If the main thread calls current() with an empty context, 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(context);
+ }
+
static DOMWrapperWorld* mainWorld();
// Associates an isolated world (see above for description) with a security
@@ -105,11 +122,19 @@ public:
int extensionGroup() const { return m_extensionGroup; }
DOMDataStore& domDataStore() { return *m_domDataStore; }
-private:
- static unsigned isolatedWorldCount;
+ static void setWorldOfInitializingWindow(DOMWrapperWorld* world)
+ {
+ ASSERT(isMainThread());
+ worldOfInitializingWindow = world;
+ }
+ // FIXME: Remove this method once we fix crbug.com/345014.
+ static bool windowIsBeingInitialized() { return !!worldOfInitializingWindow; }
+private:
DOMWrapperWorld(int worldId, int extensionGroup);
- static bool contextHasCorrectPrototype(v8::Handle<v8::Context>);
+
+ static unsigned isolatedWorldCount;
+ static DOMWrapperWorld* worldOfInitializingWindow;
const int m_worldId;
const int m_extensionGroup;
« no previous file with comments | « no previous file | Source/bindings/v8/DOMWrapperWorld.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698