| OLD | NEW |
| 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 Loading... |
| 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 17 matching lines...) Expand all Loading... |
| 63 static const int mainWorldExtensionGroup = 0; | 64 static const int mainWorldExtensionGroup = 0; |
| 64 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(int worldId, int exte
nsionGroup); | 65 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(int worldId, int exte
nsionGroup); |
| 65 ~DOMWrapperWorld(); | 66 ~DOMWrapperWorld(); |
| 66 void dispose(); | 67 void dispose(); |
| 67 | 68 |
| 68 static bool isolatedWorldsExist() { return isolatedWorldCount; } | 69 static bool isolatedWorldsExist() { return isolatedWorldCount; } |
| 69 static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld> >& worlds); | 70 static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld> >& worlds); |
| 70 | 71 |
| 71 static DOMWrapperWorld* world(v8::Handle<v8::Context> context) | 72 static DOMWrapperWorld* world(v8::Handle<v8::Context> context) |
| 72 { | 73 { |
| 73 ASSERT(contextHasCorrectPrototype(context)); | |
| 74 return V8PerContextData::world(context); | 74 return V8PerContextData::world(context); |
| 75 } | 75 } |
| 76 | 76 |
| 77 // Will return null if there is no DOMWrapperWorld for the current v8::Conte
xt | 77 // Will return null if there is no DOMWrapperWorld for the current context. |
| 78 static DOMWrapperWorld* current(v8::Isolate*); | 78 static DOMWrapperWorld* current(v8::Isolate* isolate) |
| 79 { |
| 80 v8::Handle<v8::Context> context = isolate->GetCurrentContext(); |
| 81 if (context.IsEmpty()) { |
| 82 // If a worker thread calls current() with an empty context, it mean
s that there is no DOMWrapperWorld. |
| 83 if (!isMainThread()) |
| 84 return 0; |
| 85 |
| 86 // If the main thread calls current() with an empty context, it's po
ssible that |
| 87 // current() is being called while window is being initialized. |
| 88 // In order to make current() workable during the initialization pha
se, |
| 89 // we cache the world of the initializing window on worldOfInitializ
ingWindow. |
| 90 // If there is no initiazing window, worldOfInitializingWindow is 0. |
| 91 return worldOfInitializingWindow; |
| 92 } |
| 93 return world(context); |
| 94 } |
| 95 |
| 79 static DOMWrapperWorld* mainWorld(); | 96 static DOMWrapperWorld* mainWorld(); |
| 80 | 97 |
| 81 // Associates an isolated world (see above for description) with a security | 98 // Associates an isolated world (see above for description) with a security |
| 82 // origin. XMLHttpRequest instances used in that world will be considered | 99 // origin. XMLHttpRequest instances used in that world will be considered |
| 83 // to come from that origin, not the frame's. | 100 // to come from that origin, not the frame's. |
| 84 static void setIsolatedWorldSecurityOrigin(int worldID, PassRefPtr<SecurityO
rigin>); | 101 static void setIsolatedWorldSecurityOrigin(int worldID, PassRefPtr<SecurityO
rigin>); |
| 85 static void clearIsolatedWorldSecurityOrigin(int worldID); | 102 static void clearIsolatedWorldSecurityOrigin(int worldID); |
| 86 SecurityOrigin* isolatedWorldSecurityOrigin(); | 103 SecurityOrigin* isolatedWorldSecurityOrigin(); |
| 87 | 104 |
| 88 // Associated an isolated world with a Content Security Policy. Resources | 105 // Associated an isolated world with a Content Security Policy. Resources |
| 89 // embedded into the main world's DOM from script executed in an isolated | 106 // embedded into the main world's DOM from script executed in an isolated |
| 90 // world should be restricted based on the isolated world's DOM, not the | 107 // world should be restricted based on the isolated world's DOM, not the |
| 91 // main world's. | 108 // main world's. |
| 92 // | 109 // |
| 93 // FIXME: Right now, resource injection simply bypasses the main world's | 110 // FIXME: Right now, resource injection simply bypasses the main world's |
| 94 // DOM. More work is necessary to allow the isolated world's policy to be | 111 // DOM. More work is necessary to allow the isolated world's policy to be |
| 95 // applied correctly. | 112 // applied correctly. |
| 96 static void setIsolatedWorldContentSecurityPolicy(int worldID, const String&
policy); | 113 static void setIsolatedWorldContentSecurityPolicy(int worldID, const String&
policy); |
| 97 static void clearIsolatedWorldContentSecurityPolicy(int worldID); | 114 static void clearIsolatedWorldContentSecurityPolicy(int worldID); |
| 98 bool isolatedWorldHasContentSecurityPolicy(); | 115 bool isolatedWorldHasContentSecurityPolicy(); |
| 99 | 116 |
| 100 bool isMainWorld() const { return m_worldId == MainWorldId; } | 117 bool isMainWorld() const { return m_worldId == MainWorldId; } |
| 101 bool isWorkerWorld() const { return m_worldId == WorkerWorldId; } | 118 bool isWorkerWorld() const { return m_worldId == WorkerWorldId; } |
| 102 bool isIsolatedWorld() const { return MainWorldId < m_worldId && m_worldId
< IsolatedWorldIdLimit; } | 119 bool isIsolatedWorld() const { return MainWorldId < m_worldId && m_worldId
< IsolatedWorldIdLimit; } |
| 103 | 120 |
| 104 int worldId() const { return m_worldId; } | 121 int worldId() const { return m_worldId; } |
| 105 int extensionGroup() const { return m_extensionGroup; } | 122 int extensionGroup() const { return m_extensionGroup; } |
| 106 DOMDataStore& domDataStore() { return *m_domDataStore; } | 123 DOMDataStore& domDataStore() { return *m_domDataStore; } |
| 107 | 124 |
| 125 static void setWorldOfInitializingWindow(DOMWrapperWorld* world) |
| 126 { |
| 127 ASSERT(isMainThread()); |
| 128 worldOfInitializingWindow = world; |
| 129 } |
| 130 // FIXME: Remove this method once we fix crbug.com/345014. |
| 131 static bool windowIsBeingInitialized() { return !!worldOfInitializingWindow;
} |
| 132 |
| 108 private: | 133 private: |
| 134 DOMWrapperWorld(int worldId, int extensionGroup); |
| 135 |
| 109 static unsigned isolatedWorldCount; | 136 static unsigned isolatedWorldCount; |
| 110 | 137 static DOMWrapperWorld* worldOfInitializingWindow; |
| 111 DOMWrapperWorld(int worldId, int extensionGroup); | |
| 112 static bool contextHasCorrectPrototype(v8::Handle<v8::Context>); | |
| 113 | 138 |
| 114 const int m_worldId; | 139 const int m_worldId; |
| 115 const int m_extensionGroup; | 140 const int m_extensionGroup; |
| 116 OwnPtr<DOMDataStore> m_domDataStore; | 141 OwnPtr<DOMDataStore> m_domDataStore; |
| 117 }; | 142 }; |
| 118 | 143 |
| 119 } // namespace WebCore | 144 } // namespace WebCore |
| 120 | 145 |
| 121 #endif // DOMWrapperWorld_h | 146 #endif // DOMWrapperWorld_h |
| OLD | NEW |