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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/bindings/v8/DOMWrapperWorld.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 16 matching lines...) Expand all
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef DOMWrapperWorld_h 31 #ifndef DOMWrapperWorld_h
32 #define DOMWrapperWorld_h 32 #define DOMWrapperWorld_h
33 33
34 #include "bindings/v8/V8DOMActivityLogger.h" 34 #include "bindings/v8/V8DOMActivityLogger.h"
35 #include "bindings/v8/V8PerContextData.h" 35 #include "bindings/v8/V8PerContextData.h"
36 #include "platform/weborigin/SecurityOrigin.h" 36 #include "platform/weborigin/SecurityOrigin.h"
37 #include <v8.h> 37 #include "wtf/MainThread.h"
38 #include "wtf/PassRefPtr.h" 38 #include "wtf/PassRefPtr.h"
39 #include "wtf/RefCounted.h" 39 #include "wtf/RefCounted.h"
40 #include "wtf/RefPtr.h" 40 #include "wtf/RefPtr.h"
41 #include "wtf/text/WTFString.h" 41 #include "wtf/text/WTFString.h"
42 #include <v8.h>
42 43
43 namespace WebCore { 44 namespace WebCore {
44 45
45 class DOMDataStore; 46 class DOMDataStore;
46 class ScriptController; 47 class ScriptController;
47 class ExecutionContext; 48 class ExecutionContext;
48 49
49 enum WorldIdConstants { 50 enum WorldIdConstants {
50 MainWorldId = 0, 51 MainWorldId = 0,
51 // Embedder isolated worlds can use IDs in [1, 1<<29). 52 // Embedder isolated worlds can use IDs in [1, 1<<29).
52 EmbedderWorldIdLimit = (1 << 29), 53 EmbedderWorldIdLimit = (1 << 29),
53 ScriptPreprocessorIsolatedWorldId, 54 ScriptPreprocessorIsolatedWorldId,
54 WorkerWorldId, 55 WorkerWorldId,
55 }; 56 };
56 57
57 // This class represent a collection of DOM wrappers for a specific world. 58 // This class represent a collection of DOM wrappers for a specific world.
58 class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { 59 class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {
59 public: 60 public:
60 static PassRefPtr<DOMWrapperWorld> create(int worldId, int extensionGroup); 61 static PassRefPtr<DOMWrapperWorld> create(int worldId, int extensionGroup);
61 62
62 static const int mainWorldExtensionGroup = 0; 63 static const int mainWorldExtensionGroup = 0;
63 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(int worldId, int exte nsionGroup); 64 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(int worldId, int exte nsionGroup);
64 ~DOMWrapperWorld(); 65 ~DOMWrapperWorld();
65 66
66 static bool isolatedWorldsExist() { return isolatedWorldCount; } 67 static bool isolatedWorldsExist() { return isolatedWorldCount; }
67 static void getAllWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld> >& world s); 68 static void getAllWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld> >& world s);
68 69
69 static DOMWrapperWorld* world(v8::Handle<v8::Context> context) 70 static DOMWrapperWorld* world(v8::Handle<v8::Context> context)
70 { 71 {
71 ASSERT(contextHasCorrectPrototype(context)); 72 V8PerContextDataHolder* contextHolder = V8PerContextDataHolder::from(con text);
dcarney 2014/02/27 17:03:44 This ASSERT has saved us a lot of debugging in the
haraken 2014/02/28 00:06:25 Done. Reverted back the ASSERT.
72 return V8PerContextDataHolder::from(context)->world(); 73 return contextHolder ? contextHolder->world() : 0;
73 } 74 }
74 75
75 // Will return null if there is no DOMWrapperWorld for the current v8::Conte xt 76 // Will return null if there is no DOMWrapperWorld for the current v8::Conte xt
76 static DOMWrapperWorld* current(v8::Isolate*); 77 static DOMWrapperWorld* current(v8::Isolate* isolate)
78 {
79 v8::Handle<v8::Context> context = isolate->GetCurrentContext();
80 if (context.IsEmpty()) {
81 // It's possible that DOMWrapperWorld::current() is called while win dow is being initialized.
82 // To make DOMWrapperWorld::current() workable during the initializa tion phase,
83 // we cache the world of the initializing window on worldOfInitializ ingWindow.
84 // If there is no initiazing window, worldOfInitializingWindow is 0.
85 return worldOfInitializingWindow;
86 }
87 return world(context);
88 }
89
77 static DOMWrapperWorld* mainWorld(); 90 static DOMWrapperWorld* mainWorld();
78 91
79 // Associates an isolated world (see above for description) with a security 92 // Associates an isolated world (see above for description) with a security
80 // origin. XMLHttpRequest instances used in that world will be considered 93 // origin. XMLHttpRequest instances used in that world will be considered
81 // to come from that origin, not the frame's. 94 // to come from that origin, not the frame's.
82 static void setIsolatedWorldSecurityOrigin(int worldID, PassRefPtr<SecurityO rigin>); 95 static void setIsolatedWorldSecurityOrigin(int worldID, PassRefPtr<SecurityO rigin>);
83 static void clearIsolatedWorldSecurityOrigin(int worldID); 96 static void clearIsolatedWorldSecurityOrigin(int worldID);
84 SecurityOrigin* isolatedWorldSecurityOrigin(); 97 SecurityOrigin* isolatedWorldSecurityOrigin();
85 98
86 // Associated an isolated world with a Content Security Policy. Resources 99 // Associated an isolated world with a Content Security Policy. Resources
(...skipping 14 matching lines...) Expand all
101 static V8DOMActivityLogger* activityLogger(int worldId); 114 static V8DOMActivityLogger* activityLogger(int worldId);
102 115
103 bool isMainWorld() const { return m_worldId == MainWorldId; } 116 bool isMainWorld() const { return m_worldId == MainWorldId; }
104 bool isWorkerWorld() const { return m_worldId == WorkerWorldId; } 117 bool isWorkerWorld() const { return m_worldId == WorkerWorldId; }
105 bool isIsolatedWorld() const { return !isMainWorld() && !isWorkerWorld(); } 118 bool isIsolatedWorld() const { return !isMainWorld() && !isWorkerWorld(); }
106 119
107 int worldId() const { return m_worldId; } 120 int worldId() const { return m_worldId; }
108 int extensionGroup() const { return m_extensionGroup; } 121 int extensionGroup() const { return m_extensionGroup; }
109 DOMDataStore& domDataStore() { return *m_domDataStore; } 122 DOMDataStore& domDataStore() { return *m_domDataStore; }
110 123
124 static void setWorldOfInitializingWindow(DOMWrapperWorld* world)
125 {
126 ASSERT(isMainThread());
127 worldOfInitializingWindow = world;
128 }
129
111 private: 130 private:
131 DOMWrapperWorld(int worldId, int extensionGroup);
132
112 static unsigned isolatedWorldCount; 133 static unsigned isolatedWorldCount;
113 134 static DOMWrapperWorld* worldOfInitializingWindow;
114 DOMWrapperWorld(int worldId, int extensionGroup);
115 static bool contextHasCorrectPrototype(v8::Handle<v8::Context>);
116 135
117 const int m_worldId; 136 const int m_worldId;
118 const int m_extensionGroup; 137 const int m_extensionGroup;
119 OwnPtr<DOMDataStore> m_domDataStore; 138 OwnPtr<DOMDataStore> m_domDataStore;
120 }; 139 };
121 140
122 } // namespace WebCore 141 } // namespace WebCore
123 142
124 #endif // DOMWrapperWorld_h 143 #endif // DOMWrapperWorld_h
OLDNEW
« 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