| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 29 */ | |
| 30 | |
| 31 #ifndef DOMWrapperWorld_h | |
| 32 #define DOMWrapperWorld_h | |
| 33 | |
| 34 #include "bindings/v8/ScriptState.h" | |
| 35 #include "platform/weborigin/SecurityOrigin.h" | |
| 36 #include "wtf/MainThread.h" | |
| 37 #include "wtf/PassRefPtr.h" | |
| 38 #include "wtf/RefCounted.h" | |
| 39 #include "wtf/RefPtr.h" | |
| 40 #include "wtf/text/WTFString.h" | |
| 41 #include <v8.h> | |
| 42 | |
| 43 namespace WebCore { | |
| 44 | |
| 45 class DOMDataStore; | |
| 46 class ExecutionContext; | |
| 47 class ScriptController; | |
| 48 | |
| 49 enum WorldIdConstants { | |
| 50 MainWorldId = 0, | |
| 51 // Embedder isolated worlds can use IDs in [1, 1<<29). | |
| 52 EmbedderWorldIdLimit = (1 << 29), | |
| 53 ScriptPreprocessorIsolatedWorldId, | |
| 54 PrivateScriptIsolatedWorldId, | |
| 55 IsolatedWorldIdLimit, | |
| 56 WorkerWorldId, | |
| 57 TestingWorldId, | |
| 58 }; | |
| 59 | |
| 60 // This class represent a collection of DOM wrappers for a specific world. | |
| 61 class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { | |
| 62 public: | |
| 63 static PassRefPtr<DOMWrapperWorld> create(int worldId = -1, int extensionGro
up = -1); | |
| 64 | |
| 65 static const int mainWorldExtensionGroup = 0; | |
| 66 static const int privateScriptIsolatedWorldExtensionGroup = 1; | |
| 67 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(int worldId, int exte
nsionGroup); | |
| 68 ~DOMWrapperWorld(); | |
| 69 void dispose(); | |
| 70 | |
| 71 static bool isolatedWorldsExist() { return isolatedWorldCount; } | |
| 72 static void allWorldsInMainThread(Vector<RefPtr<DOMWrapperWorld> >& worlds); | |
| 73 | |
| 74 static DOMWrapperWorld& world(v8::Handle<v8::Context> context) | |
| 75 { | |
| 76 return ScriptState::from(context)->world(); | |
| 77 } | |
| 78 | |
| 79 static DOMWrapperWorld& current(v8::Isolate* isolate) | |
| 80 { | |
| 81 if (isMainThread() && worldOfInitializingWindow) { | |
| 82 // It's possible that current() is being called while window is bein
g initialized. | |
| 83 // In order to make current() workable during the initialization pha
se, | |
| 84 // we cache the world of the initializing window on worldOfInitializ
ingWindow. | |
| 85 // If there is no initiazing window, worldOfInitializingWindow is 0. | |
| 86 return *worldOfInitializingWindow; | |
| 87 } | |
| 88 return world(isolate->GetCurrentContext()); | |
| 89 } | |
| 90 | |
| 91 static DOMWrapperWorld& mainWorld(); | |
| 92 static DOMWrapperWorld& privateScriptIsolatedWorld(); | |
| 93 | |
| 94 // Associates an isolated world (see above for description) with a security | |
| 95 // origin. XMLHttpRequest instances used in that world will be considered | |
| 96 // to come from that origin, not the frame's. | |
| 97 static void setIsolatedWorldSecurityOrigin(int worldId, PassRefPtr<SecurityO
rigin>); | |
| 98 SecurityOrigin* isolatedWorldSecurityOrigin(); | |
| 99 | |
| 100 // Associated an isolated world with a Content Security Policy. Resources | |
| 101 // embedded into the main world's DOM from script executed in an isolated | |
| 102 // world should be restricted based on the isolated world's DOM, not the | |
| 103 // main world's. | |
| 104 // | |
| 105 // FIXME: Right now, resource injection simply bypasses the main world's | |
| 106 // DOM. More work is necessary to allow the isolated world's policy to be | |
| 107 // applied correctly. | |
| 108 static void setIsolatedWorldContentSecurityPolicy(int worldId, const String&
policy); | |
| 109 bool isolatedWorldHasContentSecurityPolicy(); | |
| 110 | |
| 111 bool isMainWorld() const { return m_worldId == MainWorldId; } | |
| 112 bool isPrivateScriptIsolatedWorld() const { return m_worldId == PrivateScrip
tIsolatedWorldId; } | |
| 113 bool isWorkerWorld() const { return m_worldId == WorkerWorldId; } | |
| 114 bool isIsolatedWorld() const { return MainWorldId < m_worldId && m_worldId
< IsolatedWorldIdLimit; } | |
| 115 | |
| 116 int worldId() const { return m_worldId; } | |
| 117 int extensionGroup() const { return m_extensionGroup; } | |
| 118 DOMDataStore& domDataStore() const { return *m_domDataStore; } | |
| 119 | |
| 120 static void setWorldOfInitializingWindow(DOMWrapperWorld* world) | |
| 121 { | |
| 122 ASSERT(isMainThread()); | |
| 123 worldOfInitializingWindow = world; | |
| 124 } | |
| 125 // FIXME: Remove this method once we fix crbug.com/345014. | |
| 126 static bool windowIsBeingInitialized() { return !!worldOfInitializingWindow;
} | |
| 127 | |
| 128 private: | |
| 129 DOMWrapperWorld(int worldId, int extensionGroup); | |
| 130 | |
| 131 static unsigned isolatedWorldCount; | |
| 132 static DOMWrapperWorld* worldOfInitializingWindow; | |
| 133 | |
| 134 const int m_worldId; | |
| 135 const int m_extensionGroup; | |
| 136 OwnPtr<DOMDataStore> m_domDataStore; | |
| 137 }; | |
| 138 | |
| 139 } // namespace WebCore | |
| 140 | |
| 141 #endif // DOMWrapperWorld_h | |
| OLD | NEW |