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

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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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/V8PerContextData.h" 34 #include "bindings/v8/V8PerContextData.h"
35 #include "platform/weborigin/SecurityOrigin.h" 35 #include "platform/weborigin/SecurityOrigin.h"
36 #include "wtf/MainThread.h"
36 #include "wtf/PassRefPtr.h" 37 #include "wtf/PassRefPtr.h"
37 #include "wtf/RefCounted.h" 38 #include "wtf/RefCounted.h"
38 #include "wtf/RefPtr.h" 39 #include "wtf/RefPtr.h"
39 #include "wtf/text/WTFString.h" 40 #include "wtf/text/WTFString.h"
40 #include <v8.h> 41 #include <v8.h>
41 42
42 namespace WebCore { 43 namespace WebCore {
43 44
44 class DOMDataStore; 45 class DOMDataStore;
45 class ScriptController; 46 class ScriptController;
(...skipping 15 matching lines...) Expand all
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 allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld> >& worlds); 68 static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld> >& worlds);
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));
haraken 2014/03/04 04:19:45 I removed this ASSERT for the following reasons:
72 return V8PerContextData::world(context); 72 return V8PerContextData::world(context);
73 } 73 }
74 74
75 // Will return null if there is no DOMWrapperWorld for the current v8::Conte xt 75 // Will return null if there is no DOMWrapperWorld for the current context.
76 static DOMWrapperWorld* current(v8::Isolate*); 76 static DOMWrapperWorld* current(v8::Isolate* isolate)
77 {
78 v8::Handle<v8::Context> context = isolate->GetCurrentContext();
79 if (context.IsEmpty()) {
80 // If a worker thread calls current() with an empty context, it mean s that there is no DOMWrapperWorld.
81 if (!isMainThread())
82 return 0;
83
84 // If the main thread calls current() with an empty context, it's po ssible that
85 // current() is being called while window is being initialized.
86 // In order to make current() workable during the initialization pha se,
87 // we cache the world of the initializing window on worldOfInitializ ingWindow.
88 // If there is no initiazing window, worldOfInitializingWindow is 0.
89 return worldOfInitializingWindow;
90 }
91 return world(context);
92 }
93
77 static DOMWrapperWorld* mainWorld(); 94 static DOMWrapperWorld* mainWorld();
78 95
79 // Associates an isolated world (see above for description) with a security 96 // Associates an isolated world (see above for description) with a security
80 // origin. XMLHttpRequest instances used in that world will be considered 97 // origin. XMLHttpRequest instances used in that world will be considered
81 // to come from that origin, not the frame's. 98 // to come from that origin, not the frame's.
82 static void setIsolatedWorldSecurityOrigin(int worldID, PassRefPtr<SecurityO rigin>); 99 static void setIsolatedWorldSecurityOrigin(int worldID, PassRefPtr<SecurityO rigin>);
83 static void clearIsolatedWorldSecurityOrigin(int worldID); 100 static void clearIsolatedWorldSecurityOrigin(int worldID);
84 SecurityOrigin* isolatedWorldSecurityOrigin(); 101 SecurityOrigin* isolatedWorldSecurityOrigin();
85 102
86 // Associated an isolated world with a Content Security Policy. Resources 103 // Associated an isolated world with a Content Security Policy. Resources
87 // embedded into the main world's DOM from script executed in an isolated 104 // embedded into the main world's DOM from script executed in an isolated
88 // world should be restricted based on the isolated world's DOM, not the 105 // world should be restricted based on the isolated world's DOM, not the
89 // main world's. 106 // main world's.
90 // 107 //
91 // FIXME: Right now, resource injection simply bypasses the main world's 108 // FIXME: Right now, resource injection simply bypasses the main world's
92 // DOM. More work is necessary to allow the isolated world's policy to be 109 // DOM. More work is necessary to allow the isolated world's policy to be
93 // applied correctly. 110 // applied correctly.
94 static void setIsolatedWorldContentSecurityPolicy(int worldID, const String& policy); 111 static void setIsolatedWorldContentSecurityPolicy(int worldID, const String& policy);
95 static void clearIsolatedWorldContentSecurityPolicy(int worldID); 112 static void clearIsolatedWorldContentSecurityPolicy(int worldID);
96 bool isolatedWorldHasContentSecurityPolicy(); 113 bool isolatedWorldHasContentSecurityPolicy();
97 114
98 bool isMainWorld() const { return m_worldId == MainWorldId; } 115 bool isMainWorld() const { return m_worldId == MainWorldId; }
99 bool isWorkerWorld() const { return m_worldId == WorkerWorldId; } 116 bool isWorkerWorld() const { return m_worldId == WorkerWorldId; }
100 bool isIsolatedWorld() const { return MainWorldId < m_worldId && m_worldId <= EmbedderWorldIdLimit; } 117 bool isIsolatedWorld() const { return MainWorldId < m_worldId && m_worldId <= EmbedderWorldIdLimit; }
101 118
102 int worldId() const { return m_worldId; } 119 int worldId() const { return m_worldId; }
103 int extensionGroup() const { return m_extensionGroup; } 120 int extensionGroup() const { return m_extensionGroup; }
104 DOMDataStore& domDataStore() { return *m_domDataStore; } 121 DOMDataStore& domDataStore() { return *m_domDataStore; }
105 122
123 static void setWorldOfInitializingWindow(DOMWrapperWorld* world)
124 {
125 ASSERT(isMainThread());
126 worldOfInitializingWindow = world;
127 }
128 // FIXME: Remove this method once we fix crbug.com/345014.
129 static bool windowIsBeingInitialized() { return !!worldOfInitializingWindow; }
130
106 private: 131 private:
132 DOMWrapperWorld(int worldId, int extensionGroup);
133
107 static unsigned isolatedWorldCount; 134 static unsigned isolatedWorldCount;
108 135 static DOMWrapperWorld* worldOfInitializingWindow;
109 DOMWrapperWorld(int worldId, int extensionGroup);
110 static bool contextHasCorrectPrototype(v8::Handle<v8::Context>);
111 136
112 const int m_worldId; 137 const int m_worldId;
113 const int m_extensionGroup; 138 const int m_extensionGroup;
114 OwnPtr<DOMDataStore> m_domDataStore; 139 OwnPtr<DOMDataStore> m_domDataStore;
115 }; 140 };
116 141
117 } // namespace WebCore 142 } // namespace WebCore
118 143
119 #endif // DOMWrapperWorld_h 144 #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