2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 #ifndef DOMWrapperWorld_h
32 #define DOMWrapperWorld_h
34 #include "bindings/v8/V8DOMActivityLogger.h"
35 #include "bindings/v8/V8PerContextData.h"
36 #include "platform/weborigin/SecurityOrigin.h"
38 #include "wtf/PassRefPtr.h"
39 #include "wtf/RefCounted.h"
40 #include "wtf/RefPtr.h"
41 #include "wtf/text/WTFString.h"
46 class ScriptController;
47 class ExecutionContext;
49 enum WorldIdConstants {
51 EmbedderWorldIdLimit = (1 << 29),
52 ScriptPreprocessorIsolatedWorldId
55 // This class represent a collection of DOM wrappers for a specific world.
56 class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {
58 static const int mainWorldExtensionGroup = 0;
59 static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(int worldId, int extensionGroup);
62 static bool isolatedWorldsExist() { return isolatedWorldCount; }
63 static bool isIsolatedWorldId(int worldId) { return worldId > MainWorldId; }
64 static void getAllWorlds(Vector<RefPtr<DOMWrapperWorld> >& worlds);
66 void setIsolatedWorldField(v8::Handle<v8::Context>);
68 static DOMWrapperWorld* isolatedWorld(v8::Handle<v8::Context> context)
70 ASSERT(contextHasCorrectPrototype(context));
71 return V8PerContextDataHolder::from(context)->isolatedWorld();
74 // Will return null if there is no DOMWrapperWorld for the current v8::Context
75 static DOMWrapperWorld* current();
77 // Associates an isolated world (see above for description) with a security
78 // origin. XMLHttpRequest instances used in that world will be considered
79 // to come from that origin, not the frame's.
80 static void setIsolatedWorldSecurityOrigin(int worldID, PassRefPtr<SecurityOrigin>);
81 static void clearIsolatedWorldSecurityOrigin(int worldID);
82 SecurityOrigin* isolatedWorldSecurityOrigin();
84 // Associated an isolated world with a Content Security Policy. Resources
85 // embedded into the main world's DOM from script executed in an isolated
86 // world should be restricted based on the isolated world's DOM, not the
89 // FIXME: Right now, resource injection simply bypasses the main world's
90 // DOM. More work is necessary to allow the isolated world's policy to be
92 static void setIsolatedWorldContentSecurityPolicy(int worldID, const String& policy);
93 static void clearIsolatedWorldContentSecurityPolicy(int worldID);
94 bool isolatedWorldHasContentSecurityPolicy();
96 // Associate a logger with the world identified by worldId (worlId may be 0
97 // identifying the main world).
98 static void setActivityLogger(int worldId, PassOwnPtr<V8DOMActivityLogger>);
99 static V8DOMActivityLogger* activityLogger(int worldId);
101 bool isMainWorld() const { return m_worldId == MainWorldId; }
102 bool isIsolatedWorld() const { return isIsolatedWorldId(m_worldId); }
104 int worldId() const { return m_worldId; }
105 int extensionGroup() const { return m_extensionGroup; }
106 DOMDataStore& isolatedWorldDOMDataStore() const
108 ASSERT(isIsolatedWorld());
109 return *m_domDataStore;
111 v8::Handle<v8::Context> context(ScriptController&);
113 static void setInitializingWindow(bool);
116 static unsigned isolatedWorldCount;
117 static PassRefPtr<DOMWrapperWorld> createMainWorld();
118 static bool contextHasCorrectPrototype(v8::Handle<v8::Context>);
120 DOMWrapperWorld(int worldId, int extensionGroup);
123 const int m_extensionGroup;
124 OwnPtr<DOMDataStore> m_domDataStore;
126 friend DOMWrapperWorld* mainThreadNormalWorld();
129 DOMWrapperWorld* mainThreadNormalWorld();
131 } // namespace WebCore
133 #endif // DOMWrapperWorld_h